0

我正在尝试修改 BluetoothChat 示例应用程序。我只是想通过按下按钮发送消息,然后在文本视图中显示响应。我知道连接工作正常,应用程序之前运行得非常好,但是当应用程序崩溃时,稍微改变程序(为了在文本视图中显示收到的消息)。所有的代码都是一样的,我发现这个段是导致程序崩溃的原因,就在建立连接之后

case MESSAGE_READ:
            Log.i(TAG, "READING");
            String readMessage = (String) msg.obj;

            //writeOutput(readMessage);

            break;

当我删除对写入输出函数的调用时,程序运行完美......

public void writeOutput(String readmessage){

    //Recieves the string returned from the handler and displays it accordingly

    display.setText("");
    display.setText(readmessage);




}

有任何想法吗?这也是我的 LogCat 文件

07-12 09:55:35.439: I/BluetoothChatService(17267): BEGIN mConnectedThread
-07-12 09:55:35.439: I/BluetoothChat(17267): MESSAGE_STATE_CHANGE: 3
-07-12 09:55:35.525: I/BluetoothChat(17267): READING
-07-12 09:55:35.525: D/AndroidRuntime(17267): Shutting down VM
-07-12 09:55:35.525: W/dalvikvm(17267): threadid=1: thread exiting with uncaught exception 
-07-12 09:55:35.525: E/AndroidRuntime(17267): FATAL EXCEPTION: main
-07-12 09:55:35.525: E/AndroidRuntime(17267): java.lang.NullPointerException
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at com.example.android.BluetoothChat.BluetoothChat.writeOutput(BluetoothChat.java:344)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at com.example.android.BluetoothChat.BluetoothChat$1.handleMessage(BluetoothChat.java:255)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at android.os.Handler.dispatchMessage(Handler.java:99)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at android.os.Looper.loop(Looper.java:130)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at android.app.ActivityThread.main(ActivityThread.java:3906)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at java.lang.reflect.Method.invokeNative(Native Method)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at java.lang.reflect.Method.invoke(Method.java:507)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
-07-12 09:55:35.525: E/AndroidRuntime(17267):   at dalvik.system.NativeStart.main(Native Method) -
4

0 回答 0