我; m開發一個android應用程序,使操作欄透明,並在操作欄上放置一個後退按鈕。當我完成代碼顯示停止工作。操作欄上的Android錯誤?
我的代碼是
public class Song_List extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_song__list);
ActionBar ab = getActionBar();
ab.setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// app icon in action bar clicked; go home
Intent i=new Intent(Song_List.this, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
日誌貓是這樣的......
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jithin.myapplication/com.example.jithin.myapplication.Song_List}: 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:2426)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
任何人都可以建議我一個代碼,使我的行動bartransparent,並顯示在此一回按鈕移到..謝謝您
代替getActionBar() –