私は、エラーを取得しています:このメソッドを使用する方法getActionBar()。setDisplayHomeAsUpEnabled(true);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_peripheral);
getActionBar().setDisplayHomeAsUpEnabled(true);//on this line i am getting error
mListViewHeader = (View) getLayoutInflater().inflate(R.layout.peripheral_list_services_header, null, false);
connectViewsVariables();
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
mDeviceRSSI = intent.getIntExtra(EXTRAS_DEVICE_RSSI, 0) + " db";
mDeviceNameView.setText(mDeviceName);
mDeviceAddressView.setText(mDeviceAddress);
mDeviceRssiView.setText(mDeviceRSSI);
getActionBar().setTitle(mDeviceName);
// mListView.addHeaderView(mListViewHeader);
// mListView.setOnItemClickListener(listClickListener);
}
Logcat:
time: Shutting down VM
06-27 11:52:11.363 31628-31628/com.example.android.bleiqn E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.bleiqn, PID: 31628
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.bleiqn/com.example.android.bleiqn.PeripheralActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
at com.example.android.bleiqn.PeripheralActivity.onCreate(PeripheralActivity.java:32)
at android.app.Activity.performCreate(Activity.java:6303)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
どのように私はそれを解決することができますか?
チェックこれをhttps://stackoverflow.com/questions/34278878/ハウツー提供ツールバーを使用したナビゲーションツールバーのホームボタンオンv7ツールバーツールバーを最初に設定する必要があります。 – amarok