是什么导致nullpointerexception:由代码引起或不?

时间:2013-02-25 09:41:53

标签: android

我安装了Acra,因此我有时会从应用崩溃的设备收到错误日志。 我解决了其中的一些,但仍然存在4种nullpointerexceptions ,我似乎无法跟踪导致它们的原因..这是我的代码还是其他什么?似乎无法弄明白。

这些永远不会发生在我自己的设备上,而是发生在我通过报告收到的其他设备上......

//ERROR 1
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package.game/com.package.game.Answer}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
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:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.package.game.Answer.onCreate(Answer.java:93)
//line 93 = font = Typeface.createFromAsset(getAssets(), "font.ttf");

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
... 11 more
java.lang.NullPointerException
at com.package.game.Answer.onCreate(Answer.java:93)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
at android.app.ActivityThread.access$2200(ActivityThread.java:119)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
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:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)

// ERROR 2
java.lang.NullPointerException
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at com.package.game.Answer.mark(Answer.java:430)
// 430 = Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());

at com.package.game.Answer.onClick(Answer.java:389)
at android.view.View.performClick(View.java:2391)
at android.view.View.onTouchEvent(View.java:4206)
at android.view.View.dispatchTouchEvent(View.java:3736)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:855)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:887)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:887)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:887)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:887)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1662)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1110)
at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1646)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1708)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
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:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

//ERROR 3
java.lang.NullPointerException
at android.webkit.WebViewCore.didFirstLayout(WebViewCore.java:1617)
at android.webkit.BrowserFrame.nativeStopLoading(Native Method)
at android.webkit.BrowserFrame.stopLoading(BrowserFrame.java:778)
at android.webkit.WebViewCore.stopLoading(WebViewCore.java:1119)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:728)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:471)
at java.lang.Thread.run(Thread.java:1060)


//ERROR 4

java.lang.NullPointerException
at com.package.game.CustomArrayAdapter.getView(CustomArrayAdapter.java:75)
//75 = int width = bitmapOrg.getWidth();

at android.widget.AbsListView.obtainView(AbsListView.java:1435)
at android.widget.GridView.makeAndAddView(GridView.java:1222)
at android.widget.GridView.makeRow(GridView.java:268)
at android.widget.GridView.fillDown(GridView.java:221)
at android.widget.GridView.fillFromTop(GridView.java:340)
at android.widget.GridView.layoutChildren(GridView.java:1114)
at android.widget.AbsListView.onLayout(AbsListView.java:1265)
at android.view.View.layout(View.java:7212)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7212)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7212)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7212)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
at android.os.Handler.dispatchMessage(Handler.java:99)
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:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:0)

尝试初始化String变量,然后再次检查代码的值......

String xyz="";

答案 1 :(得分:0)

你还应该包括Answer.java,让我们看看它有什么问题。有时,日志说出应用程序出错的哪一行是不准确的。错误可能在第93行,也可能在第92行。请发布您的代码。这会有很大的帮助。