binary xml file line#7:error inflating class

错误代码,然后贴上xml文件:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<com.example.browserstation.touchmove
    android:id="@+id/view1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Button" />


view名肯定没错,路径也没错,换另一个View就没错,换这个就错了。touchmove单独可运行

2个回答

guangtouhaky
guangtouhaky 都说了名称路劲肯定都没错了,添加同一包下的另一个View一点问题没有。
5 年多之前 回复
guangtouhaky
guangtouhaky 都说了名称路劲肯定都没错了,添加同一包下的另一个VIew
5 年多之前 回复

package com.example.browserstation;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

public class touchmove extends View{
private int start_x;
private final int width = MainActivity.screenWidth;
private int height ;
private int backwidth;

private int ori_x = 0;                  //点击屏幕原始坐标,当前坐标和位移数据
private int ori_y = 0;
private int cur_x = 0;
private int cur_y = 0;
private int del_x = 0;
private int del_y = 0;

private Bitmap bmp_back;
private Bitmap bmp_bg1;
private Bitmap bmp_draw0;
private Bitmap bmp_draw1;
private Boolean flag_move = false;
private Boolean flag_temp = false;
private int index = 0;

private Context c;
private TimerTask ttsk = new TimerTask(){

    @Override
    public void run() {
        // TODO Auto-generated method stub
        if(flag_move)h.sendEmptyMessage(0x888);
    }
};
final Handler h = new Handler(){                  //处理信息,背景移动
    public void handleMessage(Message msg){
        if(msg.what == 0x888){
            if(start_x < (backwidth - width-2)){
                flag_temp = false;
                start_x += 3;
            }else if(start_x < backwidth - 3){
                start_x += 3;
                flag_temp = true;
            }else{
                if(index>0){
                    backwidth = bmp_back.getWidth();
                    index = 0;
                }else {
                    backwidth = bmp_bg1.getWidth();
                    index += 1;
                }
                start_x = 0;
                flag_temp = false;
                flag_move = false;
            }
        }
        invalidate();
    }
};
private Timer timer;

public touchmove(Context context) {
    super(context);
    c = context;
    bmp_back = BitmapFactory.decodeResource(getResources(), R.drawable.mainback);
    bmp_back = new zoompicture(bmp_back,bmp_back.getWidth(),MainActivity.screenHeight).getOutbtm();
    bmp_bg1 = BitmapFactory.decodeResource(getResources(), R.drawable.bg1);
    bmp_bg1 = new zoompicture(bmp_bg1,bmp_bg1.getWidth(),MainActivity.screenHeight).getOutbtm();
    start_x = 0;
    backwidth = bmp_back.getWidth();
    height = MainActivity.screenHeight;
    bmp_draw0 = bmp_back;
    bmp_draw1 = bmp_back;
    timer = new Timer();
    timer.schedule(new TimerTask(){

        @Override
        public void run() {
            // TODO Auto-generated method stub
            if(flag_move){
                h.sendEmptyMessage(0x888);
            }
        }

    }, 0, 100);
}

public touchmove(Context context, AttributeSet attrs) {
    super(context,attrs);
    // TODO Auto-generated constructor stub
    c = context;
    bmp_back = BitmapFactory.decodeResource(getResources(), R.drawable.mainback);
    bmp_back = new zoompicture(bmp_back,bmp_back.getWidth(),MainActivity.screenHeight).getOutbtm();
    bmp_bg1 = BitmapFactory.decodeResource(getResources(), R.drawable.bg1);
    bmp_bg1 = new zoompicture(bmp_bg1,bmp_bg1.getWidth(),MainActivity.screenHeight).getOutbtm();
    start_x = 0;
    backwidth = bmp_back.getWidth();
    height = MainActivity.screenHeight;
    bmp_draw0 = bmp_back;
    bmp_draw1 = bmp_back;
    timer.schedule(new TimerTask(){

        @Override
        public void run() {
            // TODO Auto-generated method stub
            if(flag_move){
                h.sendEmptyMessage(0x888);
            }
        }

    }, 0, 100);
}
public touchmove(Context context, AttributeSet attrs, int delStyle) {
    super(context,attrs,delStyle);
    // TODO Auto-generated constructor stub
    c = context;
    bmp_back = BitmapFactory.decodeResource(getResources(), R.drawable.mainback);
    bmp_back = new zoompicture(bmp_back,bmp_back.getWidth(),MainActivity.screenHeight).getOutbtm();
    bmp_bg1 = BitmapFactory.decodeResource(getResources(), R.drawable.bg1);
    bmp_bg1 = new zoompicture(bmp_bg1,bmp_bg1.getWidth(),MainActivity.screenHeight).getOutbtm();
    start_x = 0;
    backwidth = bmp_back.getWidth();
    height = MainActivity.screenHeight;
    bmp_draw0 = bmp_back;
    bmp_draw1 = bmp_back;
    timer.schedule(new TimerTask(){

        @Override
        public void run() {
            // TODO Auto-generated method stub
            if(flag_move){
                h.sendEmptyMessage(0x888);
            }
        }

    }, 0, 100);
}

/* (non-Javadoc)
 * @see android.view.View#onTouchEvent(android.view.MotionEvent)
 */
@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = event.getAction();
    switch(action){
    case MotionEvent.ACTION_DOWN:ori_x = (int)event.getX();ori_y = (int)event.getY();
    Log.v("ori_x :",""+ori_x);
        return true;
    case MotionEvent.ACTION_MOVE:
        break;
    case MotionEvent.ACTION_UP:cur_x = (int)event.getX();cur_y = (int)event.getY();
    del_x = cur_x - ori_x;del_y = cur_y - ori_y;
    if(del_x < -50){
        flag_move = true;
    };Log.v("delx: ",""+del_x);
        break;
    }
    // TODO Auto-generated method stub
    return super.onTouchEvent(event);
}

/* (non-Javadoc)
 * @see android.view.View#onDraw(android.graphics.Canvas)
 */
@Override
protected void onDraw(Canvas canvas) {
    if(!flag_temp){
        switch(index){
        case 0:bmp_draw0 = Bitmap.createBitmap(bmp_back,start_x,0,width,height);
        bmp_draw1 = bmp_draw0;
        canvas.drawBitmap(bmp_draw0,0,0,new Paint());
            break;
        case 1:bmp_draw0 = Bitmap.createBitmap(bmp_bg1,start_x,0,width,height);
        bmp_draw1 = bmp_draw0;
        canvas.drawBitmap(bmp_draw0,0,0,new Paint());
            break;
        }
    }else{
        switch(index){
        case 0:bmp_draw0 = Bitmap.createBitmap(bmp_back,start_x,0,bmp_back.getWidth()-start_x,height);
        bmp_draw1 = Bitmap.createBitmap(bmp_bg1,0,0,start_x+width-backwidth,height);
        canvas.drawBitmap(bmp_draw0,0,0,new Paint());
        canvas.drawBitmap(bmp_draw1, width-bmp_draw1.getWidth(),0, new Paint());
         break;
        case 1:bmp_draw0 = Bitmap.createBitmap(bmp_bg1,start_x,0,bmp_bg1.getWidth()-start_x,height);
        bmp_draw1 = Bitmap.createBitmap(bmp_back,0,0,start_x+width-backwidth,height);
        canvas.drawBitmap(bmp_draw0,0,0,new Paint());
        canvas.drawBitmap(bmp_draw1, width-bmp_draw1.getWidth(),0, new Paint());
         break;
        }
    }
    Log.v("v","draw1:"+bmp_draw0.getWidth()+"draw2:"+bmp_draw1.getWidth()+"  strat_x"+start_x);
    // TODO Auto-generated method stub
    super.onDraw(canvas);
}

}

guangtouhaky
guangtouhaky 这个是touchmove,里面三个构造函数都重载了,xml文件的名称路径也都没错,报错说的是error inflating就是路径View名那行的错误
5 年多之前 回复
guangtouhaky
guangtouhaky 这个是touchmove,里面三个构造函数都重载了,xml文件的名称路径也都没错,报错说的是error inflating就是路径View名那行的错误
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问