我的应用程序崩溃了,我似乎无法解决。
我像这样从资源中获得位图。
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.map_distance_tag);
现在,当从该位图创建位图时,这似乎在极少数设备上存在问题。例如...
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
NullPointerException
当它创建类的Bitmap
第 468行时,我得到Bitmap
了一个,我已经查看了它,当它从其源位图设置新位图的密度比例时。
// The new bitmap was created from a known bitmap source so assume that
467 // they use the same density scale
468 bitmap.setDensityScale(source.getDensityScale());
现在我似乎无法重新创建问题,但是当在原始位图上调用 getWidth() 时我没有得到异常的事实告诉我源不为空。
这是整个堆栈跟踪。
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.my.app/com.my.app.recording.TrackingActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at com.my.app.maps.MapFragment.createTabOverlay(MapFragment.java:663)
at com.my.app.maps.MapFragment.addMarkersForToolType(MapFragment.java:474)
at com.my.app.maps.MapFragment.onActivityCreated(MapFragment.java:405)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1468)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:931)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551)
at com.my.app.recording.TrackingActivity.onStart(TrackingActivity.java:272)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
at android.app.Activity.performStart(Activity.java:3781)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
... 11 more
我的想法
不包括针对不同屏幕密度的不同位图可能与我有关吗?提供的所有位图都用于 mdpi 屏幕。
我注意到还有一个 BackStackRecord。当用户按下时,这会崩溃吗?
提前致谢