親ビューのコードで、その中に更新ボタンがあります。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("Tab1")
.setIndicator("All", getResources().getDrawable(R.drawable.all))
.setContent(new Intent(this, All.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec("Tab2")
.setIndicator("One", getResources().getDrawable(android.R.drawable.one))
.setContent(new Intent(this, One.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec("Tab3")
.setIndicator("Two",getResources().getDrawable(android.R.drawable.two))
.setContent(new Intent(this, Two.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec("Tab4")
.setIndicator("Three",getResources().getDrawable(android.R.drawable.three))
.setContent(new Intent(this, Three.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.getTabWidget().bringToFront();
setContentView(tabHost);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title_bar);
tabHost.setCurrentTab(0);
}
そして、各子ビューにボタンを定義します。これを使用します
refreshButton = (ImageButton) getParent().findViewById(R.id.refresh);
親ビューでボタンを取得しますが、refreshButton は常に null で、例外があります: java.lang.RuntimeException:Unable to start activity ComponentInfo{ParentView}:java.lang.NullPointerException.
どうすればこれを修正できますか。ありがとうございました!