2014-11-30 2 views
0

DialogTabhost을 사용하여 사용자가 Dialog 내부를 레이아웃으로 전환 할 수 있도록하려고합니다. 그러나 나는 항상 NullPointerException을 얻는다. 어떤 충고? 또는 그것을 올바르게하는 방법?Dialog에서 TabHost를 사용하는 NullPointerException? 그것을 올바르게하는 방법?

대화 방법 :

public void dialog(){ 

    final Dialog d = new Dialog(this); 
    d.setTitle("Dialog); 
    d.setContentView(R.layout.dialog); 
    d.setCanceledOnTouchOutside(false); 

    TabHost tabHost = (TabHost) d.findViewById(android.R.id.tabhost); 
    Button b_set = (Button) d.findViewById(R.id.b_choose); 
    Button b_cancel = (Button) d.findViewById(R.id.b_cancel); 

    tabHost.setup();  //Here is the problem 

    TabHost.TabSpec tab1 = tabHost.newTabSpec("Favs"); 
    TabHost.TabSpec tab2 = tabHost.newTabSpec("All"); 

    tab1.setIndicator("NEWTAB"); 
    tab1.setContent(new Intent(this,Tab1Activity.class)); 

    tab2.setIndicator("NEWTAB"); 
    tab2.setContent(new Intent(this,Tab2Activity.class)); 

    tabHost.addTab(tab1); 
    tabHost.addTab(tab2); 

    d.show(); 
    } 

Dialog.xml :

LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 

<TabHost 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/tabHost"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"></TabWidget> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

</LinearLayout> 

로그 캣 :

  11-30 14:48:06.661 7157-7157/com.test.app E/AndroidRuntime﹕ FATAL EXCEPTION: main 
     java.lang.NullPointerException 
     at com.test.app.Main.dialog (Main.java:269) 
     at com.test.app.Main$1.onClick(Main.java:139) 
     at android.view.View.performClick(View.java:4475) 
     at android.view.View$PerformClick.run(View.java:18786) 
     at android.os.Handler.handleCallback(Handler.java:730) 
     at android.os.Handler.dispatchMessage(Handler.java:92) 
     at android.os.Looper.loop(Looper.java:176) 
     at android.app.ActivityThread.main(ActivityThread.java:5419) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) 
     at dalvik.system.NativeStart.main(Native Method) 

답변

1
TabHost tabHost = (TabHost) d.findViewById(R.id.tabHost); 
,174,

ID는 대소 문자를 구분합니다.

+0

mg, 감사를 보지 못했습니다. 문제가 해결되었습니다. – Megaetron

관련 문제