我有一个片段从活动中调用loadImagpicker但是当点击图像视图时它会崩溃。我一直在做活动的所有事情,我创建了一个回调,所以我可以检索Image Uri,如果它的好处是我的代码。
public ImagePickerCallback mCallback;
private static final int GALLERY_REQUEST = 1;
public interface ImagePickerCallback{
void onImageSelected(Uri imageUri);
}
public BluEnergyTag(){
}
public void loadImagePicker(){
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK){
mCallback.onImageSelected(data.getData());
}
}
这就是我在活动中创建loadImagePicker的方式
06-07 12:52:29.404 23839-23839/bluenergyfuel.bluenergytag E/AndroidRuntime: FATAL EXCEPTION: main
Process: bluenergyfuel.bluenergytag, PID: 23839
java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread android.app.ActivityThread.getApplicationThread()' on a null object reference
at android.app.Activity.startActivityForResult(Activity.java:4226)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4183)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at bluenergyfuel.bluenergytag.BluEnergyTag.loadImagePicker(BluEnergyTag.java:202)
at bluenergyfuel.bluenergytag.drawer.PartnerStorePost$1.onClick(PartnerStorePost.java:65)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
这是我的日志
var arr=["aaa","bbb","cccc"];
console.log(new String(arr[0]));
console.log(new String(arr[1]));
console.log(new String(arr[2]));