Android textView中的java空指针错误

Android textView中的java空指针错误,android,tabs,textview,Android,Tabs,Textview,我有以下代码: public class InfoActions extends ActivityGroup{ TabHost tabHost; TabSpec first; TabSpec second; View indicatorview1; View indicatorview2; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // ToDo add your GU

我有以下代码:

public class InfoActions extends ActivityGroup{

TabHost tabHost;
TabSpec first;
TabSpec second;


View indicatorview1;
View indicatorview2;


@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // ToDo add your GUI initialization code here
    setContentView(R.layout.infoactions);

    tabHost=(TabHost)findViewById(R.id.tabhostsynchronisation);
    tabHost.setup(getLocalActivityManager());
    tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

    indicatorview1 = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_styled, null);


    first=tabHost.newTabSpec("Tab 1");
    ((TextView)indicatorview1.findViewById(R.id.tabsText)).setText("");
    first.setIndicator(indicatorview1);
    Intent in1 = new Intent(this, com.Orange.PrepareVisits.RoadmapsOnDevice.class);
    first.setContent(in1);

    indicatorview2 = android.view.LayoutInflater.from(this).inflate(R.layout.tabs_bg_styled, null);

    second=tabHost.newTabSpec("Tab 2");
    ((TextView)indicatorview2.findViewById(R.id.tabsText)).setText("Informations");
    second.setIndicator(indicatorview2);
    Intent in2 = new Intent(this, com.Orange.Information.Informations.class);
    second.setContent(in2);

    tabHost.addTab(first);
    tabHost.addTab(second);
}

这是我的
tabs\u bg\u styled.xml

<?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:background="@drawable/tab_bg_selector"
    android:padding="10dp"
    android:gravity="center"
    android:orientation="vertical"
>
    <TextView
        android:id="@+id/tabsText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Title"
        android:textSize="10dp"
        android:textStyle="bold"
        android:textColor="@drawable/tab_text_selector"
        android:gravity="center"
    />
</LinearLayout>
这是我得到错误的一行:

 ((TextView)indicatorview1.findViewById(R.id.tabsText)).setText("");

有人知道吗?

也许试着不要把所有的工作都放在一行上(至少在它工作之前)。这将更容易调试,并尝试像这样使用充气机(我总是这样使用):


也许试着不要在一条线上做所有的工作(至少在它工作之前)。这将更容易调试,并尝试像这样使用充气机(我总是这样使用):


您已经尝试使用
TextView txtview=((TextView)指示符rview1.findViewById(R.id.tabsText));txtview.setText(“”)?不,我没有试过。问题是我并不是一直都有这个错误。有时它不做任何改变就可以工作我们更喜欢这种方式。。。。。LayoutInflater mInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);mInflater.充气(R.layout.tabs\u bg\u样式化,空);首先检查
indicatorview1
是否为null,或者
findViewById(R.id.tabsText)
是否返回null。您已经尝试使用
TextView txtview=((TextView)indicatorview1.findViewById(R.id.tabsText));txtview.setText(“”)?不,我没有试过。问题是我并不是一直都有这个错误。有时它不做任何改变就可以工作我们更喜欢这种方式。。。。。LayoutInflater mInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u INFLATER\u SERVICE);mInflater.充气(R.layout.tabs\u bg\u样式化,空);首先检查
indicatorview1
是否为空,或者
findViewById(R.id.tabsText)
是否返回空值。
 ((TextView)indicatorview1.findViewById(R.id.tabsText)).setText("");
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = inflater.inflate(R.layout.tabs_bg_styled, null);
TextView tv = (TextView)vi.findViewById(R.id.tabsText);