我正在尝试修改BluetoothChat示例应用程序。我只想按一个按钮发送消息,然后在文本视图中显示响应。我知道连接工作正常,应用程序之前运行得非常好,但是当程序崩溃时,如果稍微改变程序(为了在textview中显示收到的消息)。所有的代码完全相同,并且我发现这个段是导致程序在连接建立后崩溃的原因
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) -