2011-07-15 2 views
0

私はコンソールで見たことは例外ですが、私は解決策を見つけることができません。 ここに私のコードです:java.lang.NullPointerException android

public class MainActivity extends TabActivity { 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 


     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, Collections.class); 
     spec = tabHost.newTabSpec("Collections").setIndicator("Collections") .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, MyStampii.class); 
     spec = tabHost.newTabSpec("MyStampii").setIndicator("My Stampii") .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, Notices.class); 
     spec = tabHost.newTabSpec("Notices").setIndicator("Notices") .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, Tutorial.class); 
     spec = tabHost.newTabSpec("Tutorial").setIndicator("Tutorial") .setContent(intent); 
     tabHost.addTab(spec); 

     // Do the same for the other tabs 
     intent = new Intent().setClass(this, Settings.class); 
     spec = tabHost.newTabSpec("Settings").setIndicator("Settings") .setContent(intent); 
     tabHost.addTab(spec); 
     } 
} 

とmain.xml

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:padding="5dp" /> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" /> 
    </LinearLayout> 
</TabHost> 

、これは例外である:

[2011-07-15 09:39:19 - ddms]null 
java.lang.NullPointerException 
    at com.android.ddmlib.Client.sendAndConsume(Client.java:572) 
    at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142) 
    at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65) 
    at com.android.ddmlib.Client.getJdwpPacket(Client.java:671) 
    at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317) 
    at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263) 

任意のアイデア?とにかく助けてくれてありがとう!

+0

これが役立つかどうかわかりませんが、同様のエラーが表示されます。http://stackoverflow.com/questions/4731593/android-problems-debugging-with -the-emulator-from-eclipse – jogabonito

+1

どの行から例外がスローされますか?これは例外スタックトレース全体ですか? 「原因」はありませんか? – Gallal

+0

はい、私はかなり確信しています、それは例外的なstracktraceの例外です...そしてそれはまだ現れます – hardartcore

答えて

0

を動作するJavaファイル

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    setContentView(R.layout.tabs); 
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.win_title); 

に使用し、この

<LinearLayout android:id="@+id/l1" android:layout_width="fill_parent" android:layout_height="fill_parent" 
        android:orientation="vertical" android:padding="5dp"> 

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

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

    </LinearLayout> 

希望のようなXMLのレイアウトを作ってみますリンクはアンドロイドタブレイアウトのチュートリアルです。参考文献を参照してください:http://www.androidpeople.com/android-tabhost-tutorial-part-1

0

が、これは次のことを

関連する問題