BluetoothChat例如:NullPointerException异常 [英] BluetoothChat example: NullPointerException

查看:135
本文介绍了BluetoothChat例如:NullPointerException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
   getActionBar返回null

完整的Andr​​oid小白。我试图运行从银河S3的BluetoothChat例子,它似乎崩溃的应用程序运行的时刻。

Complete Android noob. I am trying to run the BluetoothChat example from a Galaxy S3, and it appears to crash the moment the application is run.

下面是LogCat中输出:

Here is the LogCat output:

09-14 15:47:23.400: E/AndroidRuntime(6098): FATAL EXCEPTION: main
09-14 15:47:23.400: E/AndroidRuntime(6098): java.lang.NullPointerException
09-14 15:47:23.400: E/AndroidRuntime(6098):     at com.example.android.BluetoothChat.BluetoothChat.setStatus(BluetoothChat.java:235)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at com.example.android.BluetoothChat.BluetoothChat.access$4(BluetoothChat.java:233)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at com.example.android.BluetoothChat.BluetoothChat$2.handleMessage(BluetoothChat.java:260)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at android.os.Looper.loop(Looper.java:137)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at android.app.ActivityThread.main(ActivityThread.java:4514)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at java.lang.reflect.Method.invokeNative(Native Method)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at java.lang.reflect.Method.invoke(Method.java:511)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
09-14 15:47:23.400: E/AndroidRuntime(6098):     at dalvik.system.NativeStart.main(Native Method)

code为每例中的SDK正是:

Code is exactly per the example in the SDK:

private final void setStatus(int resId) {
    final ActionBar actionBar = getActionBar();
    actionBar.setSubtitle(resId);
}

这似乎getActionBar返回null。什么可能我会做正确?

It appears getActionBar returns null. What might I be doing incorrectly?

这是唯一的第二Android应用程序我已经运行,这样下去容易对我说:)

This is only the 2nd Android app I have run, so go easy on me :)

干杯

推荐答案

解决方案在这里找到: getActionBar返回null

Solution found here: getActionBar returns null

这需要转到的onCreate()方法 bluetoothChat.java

getWindow()requestFeature(Window.FEATURE_ACTION_BAR);

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

这篇关于BluetoothChat例如:NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆