Android 图像单击imageview上的图像集,但第二次单击图像,然后强制关闭

Android 图像单击imageview上的图像集,但第二次单击图像,然后强制关闭,android,image,android-activity,android-tabhost,Android,Image,Android Activity,Android Tabhost,致命异常: 听到代码此代码是图像单击一次,然后图像是图库,以便在图像视图上显示图像,但第二次图像单击,然后强制关闭请帮助 protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); // setContentView(R.layout.add_new_student_layout); group =

致命异常:

听到代码此代码是图像单击一次,然后图像是图库,以便在图像视图上显示图像,但第二次图像单击,然后强制关闭请帮助

     protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// setContentView(R.layout.add_new_student_layout);
group = this;
View contentView = LayoutInflater.from(getParent()).inflate(
        R.layout.add_new_student_layout, null);
setContentView(contentView);

try {
    edtStudentId = (EditText) findViewById(R.id.edit_student_id);
    edtStudentJoiningDate = (EditText) 

                findViewById(R.id.edit_jonining_date);
    edtStudentName = (EditText) findViewById(R.id.edit_name);
    edtStudentAddress = (EditText) findViewById(R.id.edit_address);
    edtStudentTelephone = (EditText) findViewById(R.id.edit_telephone);
    btnSave = (Button) findViewById(R.id.btn_save);
    btnCancel = (Button) findViewById(R.id.btn_cancel);
    imgPhoto = (ImageView) findViewById(R.id.img_student_photo);

    /**
     * create DatabaseHandler object
     */
    db = new DataBaseHandler(this);
    /**
     * Reading and getting all records from database
     */
    List<Contact> contacts = db.getAllContacts();
    for (Contact cn : contacts) {
        String log = "ID:" + cn.getID() + " Name: " + cn.getName()
                + " ,Image: " + cn.getImage();

        // Writing Contacts to log
        Log.d("Result: ", log);
        // add contacts data in arrayList
        imageArry.add(cn);

    }

    /**
     * Set Data base Item into listview
     */
    /*
     * imageAdapter = new ContactImageAdapter(this,
     * R.layout.screen_list, imageArry);
     * dataList.setAdapter(imageAdapter);
     */
    /**
     * go to next activity for detail image
     */

    for (int i = 0; i < imageArry.size(); i++) {

        Contact picture = imageArry.get(i);
        // convert byte to bitmap take from contact class

        byte[] outImage = picture._image;
        ByteArrayInputStream imageStream = new ByteArrayInputStream(
                outImage);
        theImage = BitmapFactory.decodeStream(imageStream);
        imgPhoto.setImageBitmap(theImage);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    /**
     * open dialog for choose camera/gallery
     */

    final String[] option = new String[] { "Take from Camera",
            "Select from Gallery" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, option);

    builder.setTitle("Select Option");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            Log.e("Selected Item", String.valueOf(which));
            if (which == 0) {
                callCamera();
            }
            if (which == 1) {
                callGallery();
            }

        }
    });
    final AlertDialog dialog = builder.create();

    imgPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.show();

            imageArry = null;
            theImage = null;
        }
    });

    btnSave.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                addStudedntInDatabase();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    btnCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

}

粘贴您正在使用的代码问题似乎在AddNewStudent类中。张贴其代码
     protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// setContentView(R.layout.add_new_student_layout);
group = this;
View contentView = LayoutInflater.from(getParent()).inflate(
        R.layout.add_new_student_layout, null);
setContentView(contentView);

try {
    edtStudentId = (EditText) findViewById(R.id.edit_student_id);
    edtStudentJoiningDate = (EditText) 

                findViewById(R.id.edit_jonining_date);
    edtStudentName = (EditText) findViewById(R.id.edit_name);
    edtStudentAddress = (EditText) findViewById(R.id.edit_address);
    edtStudentTelephone = (EditText) findViewById(R.id.edit_telephone);
    btnSave = (Button) findViewById(R.id.btn_save);
    btnCancel = (Button) findViewById(R.id.btn_cancel);
    imgPhoto = (ImageView) findViewById(R.id.img_student_photo);

    /**
     * create DatabaseHandler object
     */
    db = new DataBaseHandler(this);
    /**
     * Reading and getting all records from database
     */
    List<Contact> contacts = db.getAllContacts();
    for (Contact cn : contacts) {
        String log = "ID:" + cn.getID() + " Name: " + cn.getName()
                + " ,Image: " + cn.getImage();

        // Writing Contacts to log
        Log.d("Result: ", log);
        // add contacts data in arrayList
        imageArry.add(cn);

    }

    /**
     * Set Data base Item into listview
     */
    /*
     * imageAdapter = new ContactImageAdapter(this,
     * R.layout.screen_list, imageArry);
     * dataList.setAdapter(imageAdapter);
     */
    /**
     * go to next activity for detail image
     */

    for (int i = 0; i < imageArry.size(); i++) {

        Contact picture = imageArry.get(i);
        // convert byte to bitmap take from contact class

        byte[] outImage = picture._image;
        ByteArrayInputStream imageStream = new ByteArrayInputStream(
                outImage);
        theImage = BitmapFactory.decodeStream(imageStream);
        imgPhoto.setImageBitmap(theImage);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    /**
     * open dialog for choose camera/gallery
     */

    final String[] option = new String[] { "Take from Camera",
            "Select from Gallery" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, option);

    builder.setTitle("Select Option");
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            Log.e("Selected Item", String.valueOf(which));
            if (which == 0) {
                callCamera();
            }
            if (which == 1) {
                callGallery();
            }

        }
    });
    final AlertDialog dialog = builder.create();

    imgPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.show();

            imageArry = null;
            theImage = null;
        }
    });

    btnSave.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                addStudedntInDatabase();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    btnCancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}