小编poi*_*ose的帖子

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

我已经尝试了Tab Layout示例,并且我还修复了示例中的少数拼写错误(并将所有活动添加到清单中).但是,当我在模拟器上运行它时,我会在第一行显示NullPointerException

tabHost.addTab(SPEC);

所以我的问题当然是.导致此异常的示例有什么问题?我正在使用Eclipse Galileo并将目标包设置为Android 1.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

    // …
Run Code Online (Sandbox Code Playgroud)

android android-tabhost

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

android-tabhost ×1