私が書いているAndroidアプリに問題があります。それはNullPointerException
のためにEclairでクラッシュするが、FroyoとGingerbreadでは問題なく動作する。誰もがNULLポインタの例外を避けるためにこれを書き換える方法を教えてもらえますか?前もって感謝します。Androidアプリ - Eclairでヌルポインタ例外を返す
編集 は、私はもともと間違ってそれを読んだことがあるかもしれない、スタックトレースとlogcatを追加し、それは私のTabWidget
可能性のように見えますか?私Home
クラスで
logcat参照このライン:
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Snow", res.getDrawable(R.drawable.weather2)).setContent(new Intent(this,FirstTab.class)));
Logcat
ERROR/AndroidRuntime(314): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wilcoxis.android.kirkwood/com.wilcoxis.android.Home}: java.lang.NullPointerException
ERROR/AndroidRuntime(314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
ERROR/AndroidRuntime(314): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
ERROR/AndroidRuntime(314): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
ERROR/AndroidRuntime(314): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
ERROR/AndroidRuntime(314): at android.os.Handler.dispatchMessage(Handler.java:99)
ERROR/AndroidRuntime(314): at android.os.Looper.loop(Looper.java:123)
ERROR/AndroidRuntime(314): at android.app.ActivityThread.main(ActivityThread.java:4363)
ERROR/AndroidRuntime(314): at java.lang.reflect.Method.invokeNative(Native Method)
ERROR/AndroidRuntime(314): at java.lang.reflect.Method.invoke(Method.java:521)
ERROR/AndroidRuntime(314): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
ERROR/AndroidRuntime(314): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
ERROR/AndroidRuntime(314): at dalvik.system.NativeStart.main(Native Method)
ERROR/AndroidRuntime(314): Caused by: java.lang.NullPointerException
ERROR/AndroidRuntime(314): at android.widget.TabWidget.onFocusChange(TabWidget.java:351)
ERROR/AndroidRuntime(314): at android.view.View.onFocusChanged(View.java:2622)
ERROR/AndroidRuntime(314): at android.view.View.handleFocusGainInternal(View.java:2445)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.handleFocusGainInternal(ViewGroup.java:404)
ERROR/AndroidRuntime(314): at android.view.View.requestFocus(View.java:3562)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.requestFocus(ViewGroup.java:976)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.requestFocus(ViewGroup.java:977)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.requestFocus(ViewGroup.java:980)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.requestFocus(ViewGroup.java:977)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:1021)
ERROR/AndroidRuntime(314): at android.view.ViewGroup.requestFocus(ViewGroup.java:980)
ERROR/AndroidRuntime(314): at android.view.View.requestFocus(View.java:3513)
ERROR/AndroidRuntime(314): at android.view.View.requestFocus(View.java:3491)
ERROR/AndroidRuntime(314): at android.widget.TabHost.setCurrentTab(TabHost.java:334)
ERROR/AndroidRuntime(314): at android.widget.TabHost.addTab(TabHost.java:213)
ERROR/AndroidRuntime(314): at com.wilcoxis.android.Home.onCreate(Home.java:83)
ERROR/AndroidRuntime(314): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
ERROR/AndroidRuntime(314): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
ERROR/AndroidRuntime(314): ... 11 more
スタックトレース
DalvikVM[localhost:8610]
Thread [<3> main] (Suspended (exception NullPointerException))
TabWidget.onFocusChange(View, boolean) line: 351
TabWidget(View).onFocusChanged(boolean, int, Rect) line: 2622
TabWidget(View).handleFocusGainInternal(int, Rect) line: 2445
TabWidget(ViewGroup).handleFocusGainInternal(int, Rect) line: 404
TabWidget(View).requestFocus(int, Rect) line: 3562
TabWidget(ViewGroup).requestFocus(int, Rect) line: 976
LinearLayout(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021
LinearLayout(ViewGroup).requestFocus(int, Rect) line: 977
TabHost(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021
TabHost(ViewGroup).requestFocus(int, Rect) line: 980
FrameLayout(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021
FrameLayout(ViewGroup).requestFocus(int, Rect) line: 977
PhoneWindow$DecorView(ViewGroup).onRequestFocusInDescendants(int, Rect) line: 1021
PhoneWindow$DecorView(ViewGroup).requestFocus(int, Rect) line: 980
PhoneWindow$DecorView(View).requestFocus(int) line: 3513
PhoneWindow$DecorView(View).requestFocus() line: 3491
TabHost.setCurrentTab(int) line: 334
TabHost.addTab(TabHost$TabSpec) line: 213
Home.onCreate(Bundle) line: 83
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2459
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2512
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 119
ActivityThread$H.handleMessage(Message) line: 1863
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4363
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
Thread [<13> Binder Thread #2] (Running)
Thread [<11> Binder Thread #1] (Running)
'最後に呼び出される関数は、String []' String []関数ではない、それは戻り値の型です。この関数はupdateData()です。また、 '例外をスローする'メソッドを宣言することも悪いです。 throwableを投げることができると明示的に宣言するだけでよい。 – Falmarri
あなたのlogcatは何を印刷しますか?関数呼び出しの後でデータがnullの場合、関数は例外を投げたことは明らかです。 – Falmarri