运行android HelloTabWidget示例时出现问题-addTab()上的NullPointerException

运行android HelloTabWidget示例时出现问题-addTab()上的NullPointerException,android,android-tabhost,Android,Android Tabhost,我已经尝试了,而且我还修复了示例中的几个拼写错误(并将所有活动添加到清单中)。然而,当我在模拟器上运行它时,我在第一行得到一个NullPointerException,它说 </application> tabHost.addTab(spec) </application> 当然,我的问题是。该示例有什么问题会导致此异常?我正在使用EclipseGalileo,并将目标包设置为Android1.5。到目前为止,我在android开发站点上的其他示例中没有遇到其他问题

我已经尝试了,而且我还修复了示例中的几个拼写错误(并将所有活动添加到清单中)。然而,当我在模拟器上运行它时,我在第一行得到一个NullPointerException,它说

</application>
tabHost.addTab(spec)

</application>
当然,我的问题是。该示例有什么问题会导致此异常?我正在使用EclipseGalileo,并将目标包设置为Android1.5。到目前为止,我在android开发站点上的其他示例中没有遇到其他问题

package com.example.hellotabwidget;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;

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

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

    // Create an Intent to launch an Activity for the tab (to be reused)
    //final Context context = getApplicationContext();
    intent = new Intent().setClass(this, ArtistsActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("artists").setIndicator("Artists",
            res.getDrawable(R.drawable.ic_tab_artists))
            .setContent(intent);
    tabHost.addTab(spec); //******** NullPointerException after running this line

    // Do the same for the other tabs
    intent = new Intent().setClass(this, AlbumsActivity.class);
    spec = tabHost.newTabSpec("albums").setIndicator("Albums",
            res.getDrawable(R.drawable.ic_tab_artists))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SongsActivity.class);
    spec = tabHost.newTabSpec("songs").setIndicator("Songs",
            res.getDrawable(R.drawable.ic_tab_artists))
            .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTabByTag("artists");
}
}
</application>
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">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</LinearLayout>
</TabHost>
</application>


您应该发布更多的代码,以便我们做出更好的假设。尤其要确保您在某处实例化了tabHost。

您是否将活动放入了AndroidManifest.xml中?您必须告诉应用程序您想要显示的活动,否则您得到的只是一个错误

</application>
例如,可以将以下xml代码放入元素中:

</application>

希望这会有所帮助

</application>

-Surya Wijaya Madjid

在您的清单中尝试以下内容:

<activity android:name=".AlbumsActivity"  android:label="@string/app_name"></activity> 
    <activity android:name=".ArtistsActivity"  android:label="@string/app_name"></activity> 
    <activity android:name=".SongsActivity"  android:label="@string/app_name"></activity> 
</application>

这就是我的工作原理:

</application>
我把这行改成了“艺术家” tabHost.setCurrentTabByTag(“艺术家”)

</application>
然后在TabAndroid(主要活动名称)前面添加了一个“.”,并添加了Ngetha建议的三项活动。

</application>


我刚刚开始为Android编程,我也遇到了这个问题。我不得不说我对此感到很沮丧。按照Ngetha的建议去做对我有帮助,但我也不得不编辑我的代码。我注意到的是,Android显然不喜欢子类活动。完全我原以为通过封装所有东西可以使代码更干净,但这显然不好。我不得不将我的类移动到不同的文件中。我希望这能帮助其他新程序员解决与我相同的封装问题。

我也有同样的有线错误

</application>
试试这个:

</application>

如果您正在使用eclipse删除错误,请更改一些代码(以便应用程序重新编译),然后它就会正常工作。

更好的是,如果您遇到此类错误,请尝试Project>Clean重新生成自动生成的文件。

我也遇到了同样的问题。
</application>
我昨天开始学习教程,这是唯一一个有问题的

</application>
第一次调用空指针时,将在此行抛出空指针

</application>
tabHost.addTab(spec);
事实证明,修复程序在清单XML中

</application>
<activity android:name=".MyTabActivity"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.NoTitleBar">
    <intent-filter>
       <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


<activity android:name=".DateActivity"  android:label="@string/app_name"></activity> 
<activity android:name=".RandomNumActivity"  android:label="@string/app_name"></activity> 

最后两项活动以前不存在,它将失败。我添加了它们(多亏了上面Ngetha的建议!),效果非常好。 对于教程本身的示例,您需要添加三个艺术家、专辑和歌曲活动

</application>
我想我知道了,每个活动都需要在清单中列出,这是有道理的,我只是在遵循t的示例时没有想到它

</application>

这是真的吗?所有活动都必须在清单中吗?

我只想感谢这里发布的所有内容。解决了我的问题(和这里的其他人一样)。让这项工作发挥作用是非常令人沮丧的。他们应该把这个例子简化得更好

</application>
尝试总结所需的更改

</application>
  • 加上Ngetha说的3条活动线
  • 将所有3个活动类移动到单独的文件中。 我最后使用的示例用于我的songsativity.java文件(带有eclipse错误建议)

    </application>
    
  • 我必须创建一个res\drawable目录并将所有图标放在那里,另外我还为图标创建了3个xml文件,如“ic_tab_songs.xml”
  • 解决了当从启动的意图返回时,我在.addTab(spec)之后得到nullPointerException的问题。我没有在该活动的初始条目上获得错误

    </application>
    
    我补充道:

    </application>
    
    TabHost TabHost=(TabHost)getTabHost(); tabHost.setCurrentTab(0);//这停止了nullPointerException ..... ....
    tabHost.addTab(spec)

    我在tab小部件教程中也遇到了问题

    </application>
    
    读了这篇文章,我终于解决了这个问题,谢谢你们的回答

    </application>
    
    回到教程。。。。android开发团队可以改进他们的文档

    </application>
    
    事实上,他们告诉我们将XML活动添加到清单中,只是没有很好地指定。。以下是报价:

    </application>
    
    请注意,这并不使用布局 文件只要创建一个文本视图,就可以了 选择一些文本并将其设置为内容。 为三个项目中的每一个复制此项 活动,并添加相应的 安卓系统的标签 清单文件

    </application>
    

    嘿,执行以下步骤,我确信您的问题会解决:-

    </application>
    
    创建一个类HelloTabWidget.java

    </application>
    
    package com.pericent;             //this is package name
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TabHost;
    
    public class HelloTabWidget extends TabActivity  {
    
    private String TAG="HelloTabWidget";
    
    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,ArtistsActivity.class);
      Log.v(TAG,"---artist activity is called---");
    
      // Initialize a TabSpec for each tab and add it to the TabHost
      spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
      tabHost.addTab(spec);
    
    
      // Do the same for the other tabs
      intent = new Intent().setClass(this,AlbumsActivity.class);
      Log.v(TAG,"---album activity is called---");
      spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
      tabHost.addTab(spec);
    
      intent = new Intent().setClass(this, SongsActivity.class);
      Log.v(TAG,"---song activity is called---");
      spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
      tabHost.addTab(spec);
    
      }
    
    }
    
    package com.pericent;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class ArtistsActivity extends Activity {
     private String TAG="ArtistsActivity";
        /** Called when the activity is first created. */
        @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview=new TextView(this);
            textview.setText("This is Artist Activity");
            setContentView(textview);
            Log.v(TAG,"---in artist activity---");
        }
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class AlbumsActivity extends Activity{
        private String TAG="AlbumsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_album=new TextView(this);
            textview_album.setText("This is album activity");
            setContentView(textview_album);
            Log.v(TAG,"---in album activity---");
        }
    
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class SongsActivity extends Activity{
        private String TAG="SongsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_song=new TextView(this);
            textview_song.setText("This is song activity");
            setContentView(textview_song);
            Log.v(TAG,"---in songs activity---");
        }
    
    }
    
    创建第二个活动:ArtistActivity.java

    </application>
    
    package com.pericent;             //this is package name
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TabHost;
    
    public class HelloTabWidget extends TabActivity  {
    
    private String TAG="HelloTabWidget";
    
    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,ArtistsActivity.class);
      Log.v(TAG,"---artist activity is called---");
    
      // Initialize a TabSpec for each tab and add it to the TabHost
      spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
      tabHost.addTab(spec);
    
    
      // Do the same for the other tabs
      intent = new Intent().setClass(this,AlbumsActivity.class);
      Log.v(TAG,"---album activity is called---");
      spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
      tabHost.addTab(spec);
    
      intent = new Intent().setClass(this, SongsActivity.class);
      Log.v(TAG,"---song activity is called---");
      spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
      tabHost.addTab(spec);
    
      }
    
    }
    
    package com.pericent;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class ArtistsActivity extends Activity {
     private String TAG="ArtistsActivity";
        /** Called when the activity is first created. */
        @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview=new TextView(this);
            textview.setText("This is Artist Activity");
            setContentView(textview);
            Log.v(TAG,"---in artist activity---");
        }
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class AlbumsActivity extends Activity{
        private String TAG="AlbumsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_album=new TextView(this);
            textview_album.setText("This is album activity");
            setContentView(textview_album);
            Log.v(TAG,"---in album activity---");
        }
    
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class SongsActivity extends Activity{
        private String TAG="SongsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_song=new TextView(this);
            textview_song.setText("This is song activity");
            setContentView(textview_song);
            Log.v(TAG,"---in songs activity---");
        }
    
    }
    
    创建第三个活动:AlbumsActivity.java

    </application>
    
    package com.pericent;             //this is package name
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TabHost;
    
    public class HelloTabWidget extends TabActivity  {
    
    private String TAG="HelloTabWidget";
    
    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,ArtistsActivity.class);
      Log.v(TAG,"---artist activity is called---");
    
      // Initialize a TabSpec for each tab and add it to the TabHost
      spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
      tabHost.addTab(spec);
    
    
      // Do the same for the other tabs
      intent = new Intent().setClass(this,AlbumsActivity.class);
      Log.v(TAG,"---album activity is called---");
      spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
      tabHost.addTab(spec);
    
      intent = new Intent().setClass(this, SongsActivity.class);
      Log.v(TAG,"---song activity is called---");
      spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
      tabHost.addTab(spec);
    
      }
    
    }
    
    package com.pericent;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class ArtistsActivity extends Activity {
     private String TAG="ArtistsActivity";
        /** Called when the activity is first created. */
        @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview=new TextView(this);
            textview.setText("This is Artist Activity");
            setContentView(textview);
            Log.v(TAG,"---in artist activity---");
        }
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class AlbumsActivity extends Activity{
        private String TAG="AlbumsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_album=new TextView(this);
            textview_album.setText("This is album activity");
            setContentView(textview_album);
            Log.v(TAG,"---in album activity---");
        }
    
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class SongsActivity extends Activity{
        private String TAG="SongsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_song=new TextView(this);
            textview_song.setText("This is song activity");
            setContentView(textview_song);
            Log.v(TAG,"---in songs activity---");
        }
    
    }
    
    创建第四个活动:SongsActivity.java

    </application>
    
    package com.pericent;             //this is package name
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TabHost;
    
    public class HelloTabWidget extends TabActivity  {
    
    private String TAG="HelloTabWidget";
    
    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,ArtistsActivity.class);
      Log.v(TAG,"---artist activity is called---");
    
      // Initialize a TabSpec for each tab and add it to the TabHost
      spec = tabHost.newTabSpec("artists").setIndicator("Artists",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
      tabHost.addTab(spec);
    
    
      // Do the same for the other tabs
      intent = new Intent().setClass(this,AlbumsActivity.class);
      Log.v(TAG,"---album activity is called---");
      spec = tabHost.newTabSpec("albums").setIndicator("Albums",res.getDrawable(R.drawable.ic_tab_albums)).setContent(intent);
      tabHost.addTab(spec);
    
      intent = new Intent().setClass(this, SongsActivity.class);
      Log.v(TAG,"---song activity is called---");
      spec = tabHost.newTabSpec("songs").setIndicator("Songs",res.getDrawable(R.drawable.ic_tab_songs)).setContent(intent);
      tabHost.addTab(spec);
    
      }
    
    }
    
    package com.pericent;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class ArtistsActivity extends Activity {
     private String TAG="ArtistsActivity";
        /** Called when the activity is first created. */
        @Override
          public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            TextView textview=new TextView(this);
            textview.setText("This is Artist Activity");
            setContentView(textview);
            Log.v(TAG,"---in artist activity---");
        }
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class AlbumsActivity extends Activity{
        private String TAG="AlbumsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_album=new TextView(this);
            textview_album.setText("This is album activity");
            setContentView(textview_album);
            Log.v(TAG,"---in album activity---");
        }
    
    }
    
    package com.pericent;
    
    import android.R;
    import android.app.Activity;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.TextView;
    
    public class SongsActivity extends Activity{
        private String TAG="SongsActivity";
        @Override
        public void onCreate(Bundle savedInstance)
        {
            super.onCreate(savedInstance);
            TextView textview_song=new TextView(this);
            textview_song.setText("This is song activity");
            setContentView(textview_song);
            Log.v(TAG,"---in songs activity---");
        }
    
    }
    
    在res/drawable中创建文件夹 在此文件夹中创建3个XML文件: 这些文件的代码如下所示:-

    </application>
    
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- When selected, use grey -->
        <item android:drawable="@drawable/ic_tab_artists_grey"
              android:state_selected="true" />
        <!-- When not selected, use white-->
        <item android:drawable="@drawable/ic_tab_artists_white" />
    </selector>
    
    
    
    在上面的XML代码中,我们使用了两个图像,以下是必须保存在同一文件夹(res/drawable)中的图像

    </application>
    

    </application>
    
    这是main.xml

    </application>
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/upper">
    <TabHost 
        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">
        <HorizontalScrollView android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true" android:scrollbars="none">
               <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
         </HorizontalScrollView>
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
    </LinearLayout>
    
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.pericent"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
           <activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" >
              <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                     <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
           </activity>
           <activity android:name=".AlbumsActivity" android:label="@string/app_name"></activity>
           <activity android:name=".ArtistsActivity" android:label="@string/app_name"></activity>   
           <activity android:name=".SongsActivity" android:label="@string/app_name" ></activity>
        </application>
    </manifest> 
    
    
    
    这是AdroidManifest

    </application>
    
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/upper">
    <TabHost 
        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">
        <HorizontalScrollView android:id="@+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:fillViewport="true" android:scrollbars="none">
               <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
         </HorizontalScrollView>
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
    </LinearLayout>
    
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.pericent"
          android:versionCode="1"
          android:versionName="1.0">
        <application android:icon="@drawable/icon" android:label="@string/app_name">
           <activity android:name=".HelloTabWidget" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" >
              <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                     <category android:name="android.intent.category.LAUNCHER" />
              </intent-filter>
           </activity>
           <activity android:name=".AlbumsActivity" android:label="@string/app_name"></activity>
           <activity android:name=".ArtistsActivity" android:label="@string/app_name"></activity>   
           <activity android:name=".SongsActivity" android:label="@string/app_name" ></activity>
        </application>
    </manifest> 
    
    
    

    我想所有这些信息都会有帮助,如果你有任何问题,请随时问我。我总是很乐意帮助任何人。

    没有一行写着
    tabHost.setTab(spec),主要是因为在该示例中没有使用
    setTab()
    方法。事实上,我不能
    </application>