Problem running android HelloTabWidget example - NullPointerException on addTab()

后端 未结 12 1080
陌清茗
陌清茗 2021-01-13 17:17

I\'ve tried the Tab Layout example, and I\'ve also fixed the few typos in the example (and added all the activities to the manifest). However, when I run it on the emulator

12条回答
  •  -上瘾入骨i
    2021-01-13 17:53

    Just want to say thanks to all that posted here. Solved my problem (the same as everyone else here). It was very frustrating to get this to work. They should have really simplified the example much better.

    To try to sum up the changes needed.

    1. add the 3 activity lines Ngetha says.
    2. Move all 3 activity classes to separate files. example I ended up using for my SongsActivity.java file (with eclipse error suggestions)

      package com.example.HelloTabWidget;
      import android.app.Activity;
      import android.os.Bundle;
      import android.widget.TextView;
      public class SongsActivity extends Activity {
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          TextView textview = new TextView(this);
          textview.setText("This is the Songs tab");
          setContentView(textview);
      }
      }
      
    3. I had to create a res\drawable directory and place all icons there plus I made 3 xml files for the icons such as "ic_tab_songs.xml"

提交回复
热议问题