我正试图在左上角的操作栏中回来,但它一直让我的空指针异常,我不知道为什么这里是我的代码
这是显示后屏幕的类
ActionBar bar = getActionBar();
//for color
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#5c7afe")));
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.company_info1);
// get the action bar
android.app.ActionBar actionBar = getActionBar();
// Enabling Back navigation on Action Bar icon
actionBar.setDisplayHomeAsUpEnabled(true);
这是我的清单文件
<activity android:name="com.example.hotlinesegypt.company_info"
android:parentActivityName="com.example.hotlinesegypt.Company" >
这是我的日志猫
08-21 15:51:32.614: E/AndroidRuntime(16777): FATAL EXCEPTION: main
08-21 15:51:32.614: E/AndroidRuntime(16777): Process: mo.hot.hotlinak, PID: 16777
08-21 15:51:32.614: E/AndroidRuntime(16777): java.lang.RuntimeException: Unable to start activity ComponentInfo{mo.hot.hotlinak/com.example.hotlinesegypt.Company}: java.lang.NullPointerException
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread.access$900(ActivityThread.java:161)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.os.Handler.dispatchMessage(Handler.java:102)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.os.Looper.loop(Looper.java:157)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread.main(ActivityThread.java:5356)
08-21 15:51:32.614: E/AndroidRuntime(16777): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 15:51:32.614: E/AndroidRuntime(16777): at java.lang.reflect.Method.invoke(Method.java:515)
08-21 15:51:32.614: E/AndroidRuntime(16777): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
08-21 15:51:32.614: E/AndroidRuntime(16777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
08-21 15:51:32.614: E/AndroidRuntime(16777): at dalvik.system.NativeStart.main(Native Method)
08-21 15:51:32.614: E/AndroidRuntime(16777): Caused by: java.lang.NullPointerException
08-21 15:51:32.614: E/AndroidRuntime(16777): at com.example.hotlinesegypt.Company.onCreate(Company.java:46)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.Activity.performCreate(Activity.java:5426)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
08-21 15:51:32.614: E/AndroidRuntime(16777): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
答案 0 :(得分:0)
在我看来,您只是在这一行上弄乱了您的变量名称,您创建了名为bar的ActionBar
变量
ActionBar bar = getActionBar();
然后在此处将其称为actionBar
:
actionBar.setDisplayHomeAsUpEnabled(true);
将此行更改为:
bar.setDisplayHomeAsUpEnabled(true);
看起来像它是什么但你需要检查公司的第46行,看看它是否是我的建议