/ / APIレベル5でのNullPointerExceptionのヘルプ-android、nullpointerexception、android-tabhost、tabwidget、unhandled-exception

APIレベル5でNullPointerExceptionをサポート - アンドロイド、nullpointerexception、アンドロイド - タブホスト、タブウィジェット、未処理 - 例外

APIレベル8を使用してアプリケーションを開発しましたが、最小のSDKは3です。8を実行しているエミュレーターとDroidX、およびいくつかの友人の電話でほとんどのテストを行いました。これまでのところ問題はありません。レベル3より上のAPIを使用しなかったことも知っておく必要があります。また、タブレイアウトは、Googleが提供した例のほぼ正確なコピーでした。 ここに。したがって、レベル5 APIを備えたエミュレーターで実行すると、次のエラーが発生し、TabWidgetへの参照を除いて、どこから来たのかわかりません。

Uncaught handler: thread main exiting due to uncaught exception
java.lang.NullPointerException
at android.widget.TabWidget.dispatchDraw(TabWidget.java:206)
at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
at android.view.ViewGroup.drawChild(ViewGroup.java:1524)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
at android.view.View.draw(View.java:6539)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1526)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1256)
at android.view.View.draw(View.java:6539)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
at android.view.ViewRoot.draw(ViewRoot.java:1348)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1113)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1632)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4310)
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)


Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost();  // The activity TabHost
TabHost.TabSpec spec;  // Resusable TabSpec for each tab
Intent intent;  // Reusable Intent for each tab

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, parent.class);

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("browse").setIndicator("Browse",
res.getDrawable(R.drawable.ic_tab_browse))
.setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, bookmarks.class);
spec = tabHost.newTabSpec("bookmarks").setIndicator("Bookmarks",
res.getDrawable(R.drawable.ic_tab_bookmarks))
.setContent(intent);
tabHost.addTab(spec);

// Do the same for the other tabs
intent = new Intent().setClass(this, search.class);
spec = tabHost.newTabSpec("search").setIndicator("Search",
res.getDrawable(R.drawable.ic_tab_search))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);

回答:

回答№1は1

使用するコードがないため、多くのアドバイスを提供することは困難です。

  • あなたが使用していない場合 TabActivity、あなたが電話することを確認してください setup() あなたの TabHost それで何かをする前に。

  • 例外はから来ているので TabWidget、タブインジケーターを一時的に簡略化して、問題の特定または解決に役立つかどうかを確認してください。


回答№2については2

私のタブホストはnullPointer例外を示していました2.1は、linearLayoutに保持したときに更新されましたが、相対レイアウトを試したところ、正常に機能します。 同じ状況で立ち往生している場合は、この変更が役立つ可能性があります。