我想通过将Sherlock ActionBar
扩展到Activity
来尝试使用Sherlock Activity
,但我在getSupportActionBar()
上收到以下错误,返回null
。
05-16 10:45:22.537: E/AndroidRuntime(20631): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tzoomers.birthdaysdiary/com.tzoomers.birthdaysdiary.SyncActivity}: java.lang.NullPointerException
05-16 10:45:22.537: E/AndroidRuntime(20631): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
05-16 10:45:22.537: E/AndroidRuntime(20631): at android.app.ActivityThread.startActivityNow(ActivityThread.java:1991)
05-16 10:45:22.537: E/AndroidRuntime(20631): at
.
.
..
05-16 10:45:22.537: E/AndroidRuntime(20631): Caused by: java.lang.NullPointerException
05-16 10:45:22.537: E/AndroidRuntime(20631): at com.tzoomers.birthdaysdiary.SyncActivity.onCreate(SyncActivity.java:38)
05-16 10:45:22.537: E/AndroidRuntime(20631): at android.app.Activity.performCreate(Activity.java:4531)
05-16 10:45:22.537: E/AndroidRuntime(20631): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
我将App Theme
设置为android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
。任何人都可以告诉我为什么我会在NullPointerException
getSupportActionBar()
上SherlockActivity
获得package com.tzoomers.birthdaysdiary;
import com.actionbarsherlock.app.SherlockActivity;
import com.tzoomers.controller.BirthdaysClickOListener;
import android.os.Bundle;
import android.widget.Button;
public class SyncActivity extends SherlockActivity{
Button importFromFacebookButton, sendToDeviceButton, receiveFromDeviceButton, saveToSdCardButton, loadFromSDCardButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_sync_activity);
// requestWindowFeature(Window.FEATURE_ACTION_BAR);
importFromFacebookButton = (Button) findViewById(R.id.importFacebookButton);
sendToDeviceButton = (Button) findViewById(R.id.sendToDeviceButton);
receiveFromDeviceButton = (Button) findViewById(R.id.receiveFromDeviceButton);
importFromFacebookButton.setOnClickListener(
new BirthdaysClickOListener(ActionType.IMPORT_FACEBOOK_CONTACTS, this));
sendToDeviceButton.setOnClickListener(
new BirthdaysClickOListener(ActionType.SEND_TO_DEVICE, this));
receiveFromDeviceButton.setOnClickListener(
new BirthdaysClickOListener(ActionType.RECEIVE_FROM_DEVICE, this));
// getActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().se
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
}
@Override
public boolean onOptionsItemSelected(
com.actionbarsherlock.view.MenuItem item) {
// TODO Auto-generated method stub
return super.onOptionsItemSelected(item);
}
public enum ActionType
{
IMPORT_FACEBOOK_CONTACTS, SEND_TO_DEVICE, RECEIVE_FROM_DEVICE, SAVE_TO_SDCARD, LOAD_FROM_SDCARD
}
}
?
活动是:
{{1}}
提前致谢。
此致