致命例外:
android.view.WindowManager$BadTokenException:
Unable to add window -- token
android.app.LocalActivityManager$LocalActivityRecord@4053bfd8 is not valid; is your
activity running?
at android.view.ViewRoot.setView(ViewRoot.java:527)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:241)
10-30 17:00:28.060: E/AndroidRuntime(1921):
at com.kwuit.tuitiontracker.students.AddNewStudent$2.onClick(AddNewStudent.java:144)
at android.view.View.performClick(View.java:2485)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
听到代码此代码是图像单击一次然后图像是图库以在图像视图上获取完美的显示图像但第二次图像单击然后强制关闭请帮助
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();
}
}