私の問題は、Main.classのTextView
のテキストを変更すると、nullPointerExceptionを返します。他のアクティビティクラスからアクティビティのビューにアクセスするには
ここに私のコードです:
main.xml
<TabHost ...>
<RelativeLayout ...>
<LinearLayout ...>
<TabWidget .../>
<FrameLayout ...>
<ListView ../>
</FrameLayout>
</LinearLayout>
<LinearLayout ...>
<TextView android:id="@+id/status" ... />
</LinearLayout>
</RelativeLayout>
</TabHost>
がMain.class
....
TabHost tabHost;
TabHost.TabSpec spec;
Intent intent;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//display implementation of TabHost
....
//Contacts tab
intent = new Intent().setClass(this, Contacts.class);
spec = tabHost.newTabSpec("contacts").setIndicator("Contacts", res.getDrawable(R.drawable.ic_tab_contacts)).setContent(intent);
tabHost.addTab(spec);
}
その後ステータスのTextViewを更新するクラスは、このです:
Contacts.class
public class Contacts extends ListActivity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//gather info to display in ListView
....
updateStatus("New Status");
}
private void updateStatus(String status){
TextView labelView = (TextView) findViewById(R.id.status);
labelView.setText(status);
}
}
labelView.setText(status); Error occurs here....
Pls help me。私はネット上の任意の解決策を見つけることができません。私は、ステータスを更新する必要が ....
HERESに私のマニフェスト:事前に
...
<application ...>
<activity android:name=".Main" ... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Contacts" android:label="@string/app_name"></activity>
<activity android:name=".OtherClass" android:label="@string/app_name"></activity>
<activity android:name=".OtherClass2" android:label="@string/app_name"></activity>
</application>
...
、任意の助けに感謝します。
Sir Aki、plsはメインクラスのsStatusの実装を提供しています...私もこの解決策を試したので...しかし、私にエラーを与えます。 – jayellos
私に電話しないでください。実装ではどういう意味ですか?あなたはどんなエラーを出していますか? –
私はpublic TextView sStatusを宣言しました。しかし、CantはMain.sStatusを見つけます。 – jayellos