将字符串子字符串化并将其显示到textView的问题

时间:2019-06-20 20:18:04

标签: android

我有完美的代码

 UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read.
    @Override
    public void onReceivedData(byte[] arg0) {
        String data = null;

        try {
            data = new String(arg0, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        tvAppend(textView, data);
    }
};

我试图对字符串数据进行子字符串化并将其显示在textView中,但是我的应用程序崩溃了。我不知道为什么关于数据字符串的编码吗?

1 个答案:

答案 0 :(得分:0)

在某些情况下,从byte []到String的转换失败。

我建议您替换

COS_INSTALL_DIR/cplex/examples/src/distmippython

  String data = null;

还添加崩溃日志。