我是一个新的android开发人员,我将开发高级照片编辑器,我想从一个活动中获取图像URI,并在下一个活动中以batmap的形式获取此uri。
错误:
11-29 11:53:26.893 31513-31513 / com.burhanrashid52.photoeditor E / AndroidRuntime:致命例外:主进程:com.burhanrashid52.photoeditor,PID:31513 java.lang.RuntimeException:无法启动活动ComponentInfo {com。 burhanrashid52.photoeditor / com.burhanrashid52.photoeditor.EraserActivity}:java.lang.NullPointerException:尝试对android.app.ActivityThread.performLaunchActivity()上的空对象引用调用虚拟方法'int android.graphics.Bitmap.getHeight()' android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2754)的ActivityThread.java:2689)android.app.ActivityThread $ H.handleMessage(ActivityThread。)的android.app.ActivityThread.access $ 900(ActivityThread.java:177) java:1448)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:145)在android.app.ActivityThread.main(ActivityThread.java:5938)在java.lang.reflect.Method.invoke(本机方法)在java.lang com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)的com.android.internal.os.ZygoteInit.main(ZygoteInit.java)的.reflect.Method.invoke(Method.java:372) :1195)原因:java.lang.NullPointerException:尝试在com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的空对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()'。 )android.app.Activity.performCreate(Activity.java:6288)在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)android.app.ActivityThread.main(ActivityThread.java:5938)处的loop(Looper.java:145)java.lang.reflect.Method.invoke(Method。 java:372)在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)造成原因:java.lang .NullPointerException:尝试在com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的android.app.Activity.performCreate的null对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()' (Activity.java:6288)位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)android.app.ActivityThread.main(ActivityThread.java:5938)处的loop(Looper.java:145)java.lang.reflect.Method.invoke(Method。 java:372)在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)造成原因:java.lang .NullPointerException:尝试在com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的android.app.Activity.performCreate的null对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()' (Activity.java:6288)位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)com.android.internal.os.ZygoteInit $的java.lang.reflect.Method.invoke(Method.java:372)的main(ActivityThread.java:5938) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)上的MethodAndArgsCaller.run(ZygoteInit.java:1400)原因:java.lang.NullPointerException:尝试调用虚拟方法'int android.graphics.Bitmap .getHeight()在com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的android.app.Activity.performCreate(Activity.java:6288)处为空对象引用,位于android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)com.android.internal.os.ZygoteInit $的java.lang.reflect.Method.invoke(Method.java:372)的main(ActivityThread.java:5938) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)上的MethodAndArgsCaller.run(ZygoteInit.java:1400)原因:java.lang.NullPointerException:尝试调用虚拟方法'int android.graphics.Bitmap .getHeight()在com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的android.app.Activity.performCreate(Activity.java:6288)处为空对象引用,位于android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)由com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)引起的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)处的invoke(Method.java:372) :java.lang.NullPointerException:尝试在android.app的com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的空对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()' android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)上的.Activity.performCreate(Activity.java:6288)由com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)引起的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1400)处的invoke(Method.java:372) :java.lang.NullPointerException:尝试在android.app的com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)上的空对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()' android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)上的.Activity.performCreate(Activity.java:6288)尝试在android.app.Activity.performCreate(Activity.com)上的com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)的null对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()'。 java:6288)在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)尝试在android.app.Activity.performCreate(Activity.com)上的com.burhanrashid52.photoeditor.EraserActivity.onCreate(EraserActivity.java:107)的null对象引用上调用虚拟方法'int android.graphics.Bitmap.getHeight()'。 java:6288)在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
首次活动代码
Uri ur;
ur = Uri.parse(String.valueOf(mPhotoEditorView));
Intent intent = new Intent(EditImageActivity.this, EraserActivity.class);
//intent.putExtra("BitmapImage",convertImageToByte(ur));
intent.putExtra("key", mPhotoEditorView.toString());
Toast.makeText(getApplicationContext(), "hello baby",
Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "hello baby i am there
",Toast.LENGTH_LONG).show();
startActivity(intent);
下一个活动代码
Intent intent = getIntent();
String image_path= intent.getStringExtra("key");
Uri fileUri = Uri.parse(image_path);
// imageview.setImageURI(fileUri);
InputStream in = null;
try {
in = getContentResolver().openInputStream(fileUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap = BitmapFactory.decodeStream(in);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。