我在logcat中收到SuperNotCalledException

时间:2011-02-23 09:27:25

标签: android

这是我的代码:

第1次活动::

public class ImageExercise extends Activity {
    /** Called when the activity is first created. */

    public static int pos;
    //static int[] mThumbIds;
    //public static int[] mThumbIds;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image);
        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(new ImageAdapter(this));
        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Intent intent = new Intent(ImageExercise.this,FullImage.class);
                pos=position;
                intent.putExtra("pos", pos);
                startActivity(intent);
                //finish();
            }
        });
    }
}

class ImageAdapter extends BaseAdapter {
    static int[] mThumbIds = {
        R.drawable.sample_1, R.drawable.sample_2,
        R.drawable.sample_3, R.drawable.sample_4,
        R.drawable.sample_5, R.drawable.sample_6,
        R.drawable.sample_7, R.drawable.sample_8,
        R.drawable.sample_9,R.drawable.sample_1, 
        R.drawable.sample_2,R.drawable.sample_3,
        R.drawable.sample_4, R.drawable.sample_9,
        R.drawable.sample_5, R.drawable.sample_6,
        R.drawable.sample_7, R.drawable.sample_8
    };

    private Context mContext;

    public ImageAdapter(Context c) {
        mContext = c;
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public  View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);
        } else {
            imageView = (ImageView) convertView;
        }
        /* ImageExercise obj = new ImageExercise();
        obj.pos = position;*/
        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    // references to our images
}

第二活动::

package com.ex.dp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;

public class FullImage extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        //super.onCreate(savedInstanceState);

        setContentView(R.layout.fullimage);
        Bundle bundle= getIntent().getExtras();
        ImageView image = (ImageView) findViewById(R.id.imageView1);

        int pos = bundle.getInt("pos");
        ImageAdapter obj = new ImageAdapter(this);
        image.setImageResource(obj.mThumbIds[pos]);

        /*if(pos==0)
          {
              image.setImageResource(pos);
          }*/
    }
}

Plz帮帮我

2 个答案:

答案 0 :(得分:13)

取消注释onCreate

中的行// super.onCreate(savedInstanceState);

答案 1 :(得分:4)

每次创建活动时都必须调用超类的onCreate()。 在第二个活动中,取消注释第super.onCreate(savedInstanceState);

正如@Saurabh和@Tushar刚刚说的那样