2

我正在使用Support Actionbar. 它正在运行,MessageTemplateActivity因为当我想显示启用为时getSupportActionBar().setDisplayHomeAsUpEnabled(true);,它正在启用后退按钮。但在SyncActivity中SyncActivity,它返回getSupportActionBar() is returningnull 。. Can anyone please tell me why in

空指针异常

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)

SyncActivity.java

public class SyncActivity extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_sync_activity);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

layout_sync_activity.xml

<?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>

MessageTemplateActivity.java

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);
    }

}

layout.layout_message_template.xml

<?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>

谢谢,

4

0 回答 0