我正在使用Support Actionbar
。它正在MessageTemplateActivity
中工作,因为当我想以getSupportActionBar().setDisplayHomeAsUpEnabled(true);
显示回启用时,它会启用后退按钮。但在SyncActivity
,getSupportActionBar() is returning
null . Can anyone please tell me why in
SyncActivity`中,它返回null。
06-17 18:45:45.327: E/AndroidRuntime(25335): Caused by: java.lang.NullPointerException
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.getDisplayOptions(ActionBarImplICS.java:234)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.<init>(ActionBarImplICS.java:57)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarImplICS.<init>(ActionBarImplICS.java:46)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivityDelegateICS.createSupportActionBar(ActionBarActivityDelegateICS.java:46)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivityDelegate.getSupportActionBar(ActionBarActivityDelegate.java:83)
06-17 18:45:45.327: E/AndroidRuntime(25335): at android.support.v7.app.ActionBarActivity.getSupportActionBar(ActionBarActivity.java:66)
public class SyncActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_sync_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainSyncScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
public class MessageTemplateActivity extends ActionBarActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_message_template);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
谢谢,
答案 0 :(得分:0)
在这里找到答案:https://stackoverflow.com/a/16027689/232727 问题出现在应用于此应用程序/活动的NoTitle主题中。