Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Handler的Android蓝牙数据传输_Java_Android_Bluetooth_Inputstream - Fatal编程技术网

Java 使用Handler的Android蓝牙数据传输

Java 使用Handler的Android蓝牙数据传输,java,android,bluetooth,inputstream,Java,Android,Bluetooth,Inputstream,作为Android的初学者,我有一个愚蠢的问题。我做的应用程序,可以接收数据从蓝牙测量系统。数据传输很酷,因为我可以在Android Studio的控制台中显示它,但我需要在循环中的一个活动中显示它 蓝牙类中方法run()的部分代码(我知道input是String,在发送之前我已经将其转换为int) 活动中处理程序的代码: Handler handler = new Handler() { @Override public void handleMessage(M

作为Android的初学者,我有一个愚蠢的问题。我做的应用程序,可以接收数据从蓝牙测量系统。数据传输很酷,因为我可以在Android Studio的控制台中显示它,但我需要在循环中的一个活动中显示它

蓝牙类中方法
run()
的部分代码(我知道
input
String
,在发送之前我已经将其转换为
int

活动中处理程序的代码:

Handler handler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            textView.setText(message.what);
        }
};
在该应用程序因错误而崩溃之后:

FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: String resource ID #0x6
有人知道如何修复它吗

资源$NotFoundException:字符串资源ID#0x6

由于:

textView.setText(message.what);
线路

请参见return
int
值的类型,但
TextView.setText
需要
CharSequence
类型值

当我们将
int
值传递给
TextView.setText
方法时,系统将int值视为资源id,并在给定int没有可用资源时尝试查找它,然后它将通过
NotFoundException:String resource id

在文本视图中显示
int
值:

textView.setText(String.valueOf(message.what));
你也可以试试

textView.setText(message.what+"");

@瓦德斯:如果它工作的话很好,但重要的是如果你明白它为什么会崩溃:)我知道。我会记得下次使用:)
textView.setText(message.what+"");