Imageview 图像库上的Nullpoint异常

Imageview 图像库上的Nullpoint异常,imageview,Imageview,我正在用Android创建一个图像库应用程序,但我在运行时给了我一个空点异常。请帮我改正一下。这是我的密码 我使用Gallery和ImageSwitcher进行XML设计 当用户在ImageSwitcher上单击“多媒体资料图像在动画中移动”时,我会在此处单击 public class MainActivity extends Activity implements ViewFactory,OnItemSelectedListener{ private ImageSwitcher mswitc

我正在用Android创建一个图像库应用程序,但我在运行时给了我一个空点异常。请帮我改正一下。这是我的密码

我使用Gallery和ImageSwitcher进行XML设计

当用户在ImageSwitcher上单击“多媒体资料图像在动画中移动”时,我会在此处单击

public class MainActivity extends Activity implements ViewFactory,OnItemSelectedListener{

private ImageSwitcher mswitcher;
private Integer[] mThimId={R.drawable.fba,R.drawable.fbb,R.drawable.fbc,R.drawable.fbd,R.drawable.fbe,R.drawable.fbf,R.drawable.fbg,R.drawable.fbh,R.drawable.fbi,R.drawable.fbj};
private Integer[] mImageId={R.drawable.fba,R.drawable.fbb,R.drawable.fbc,R.drawable.fbd,R.drawable.fbe,R.drawable.fbf,R.drawable.fbg,R.drawable.fbh,R.drawable.fbi,R.drawable.fbj};
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mswitcher=(ImageSwitcher)findViewById(R.id.imageSwitcher1);
    mswitcher.setFactory(this);
    mswitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));
    mswitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in));
    Gallery g=(Gallery) findViewById(R.id.gallery1);
    g.setAdapter(new ImageAdapter(this));
    g.setOnItemSelectedListener(this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub
    mswitcher.setImageResource(mImageId[arg2]);

}

public class ImageAdapter extends BaseAdapter {
    private Context mcontext;
    public ImageAdapter(Context c) {
        // TODO Auto-generated constructor stub
        mcontext=c;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mThimId.length;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ImageView i = new ImageView(mcontext);
        i.setImageResource(mThimId[position]);
        i.setAdjustViewBounds(true);
        i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
        return null;
    }
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub
}

@Override
public View makeView() {
    // TODO Auto-generated method stub
    ImageView i = new ImageView(this);
    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
    return null;
}
}
public类MainActivity扩展活动实现ViewFactory、OnItemSelectedListener{
专用图像切换器;
私有整数[]mThimId={R.drawable.fba,R.drawable.fbb,R.drawable.fbc,R.drawable.fbd,R.drawable.fbe,R.drawable.fbf,R.drawable.fbg,R.drawable.fbh,R.drawable.fbi,R.drawable.fbj};
私有整数[]mImageId={R.drawable.fba,R.drawable.fbb,R.drawable.fbc,R.drawable.fbd,R.drawable.fbe,R.drawable.fbf,R.drawable.fbg,R.drawable.fbh,R.drawable.fbi,R.drawable.fbj};
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mswitcher=(ImageSwitcher)findViewById(R.id.imageSwitcher1);
mswitcher.setFactory(本);
mswitcher.setOutAnimation(AnimationUtils.loadAnimation(这个,android.R.anim.fade_out));
mswitcher.setinaimation(AnimationUtils.loadAnimation(这是android.R.anim.fade_in));
画廊g=(画廊)findViewById(R.id.gallery1);
g、 setAdapter(新的ImageAdapter(this));
g、 setOnItemSelectedListener(此);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.main,menu);
返回true;
}
@凌驾
已选择公共视图(AdapterView arg0、视图arg1、内部arg2、长arg3){
//TODO自动生成的方法存根
mswitcher.setImageResource(mImageId[arg2]);
}
公共类ImageAdapter扩展了BaseAdapter{
私有上下文;
公共图像适配器(上下文c){
//TODO自动生成的构造函数存根
mcontext=c;
}
@凌驾
public int getCount(){
//TODO自动生成的方法存根
返回mThimId.length;
}
@凌驾
公共对象getItem(int arg0){
//TODO自动生成的方法存根
返回arg0;
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//TODO自动生成的方法存根
ImageView i=新的ImageView(mcontext);
i、 setImageResource(mThimId[位置]);
i、 setAdjustViewBounds(真);
i、 setLayoutParams(新建Gallery.LayoutParams(LayoutParams.WRAP_内容,LayoutParams.WRAP_内容));
返回null;
}
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
@凌驾
公共视图makeView(){
//TODO自动生成的方法存根
ImageView i=新的ImageView(本);
i、 setScaleType(ImageView.ScaleType.FIT_CENTER);
i、 setLayoutParams(新的ImageSwitcher.LayoutParams(LayoutParams.MATCH_父级,LayoutParams.MATCH_父级));
返回null;
}
}
这是我的XML文件代码

 <Gallery
    android:id="@+id/gallery1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="48dp"
    android:layout_marginTop="36dp" />

<ImageSwitcher
    android:id="@+id/imageSwitcher1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="159dp"
    android:layout_marginLeft="63dp" >
</ImageSwitcher>

您应该从getView和makeView方法返回'i'而不是null