Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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 此处理程序可能是静态的,或者蓝牙处理程序可能发生泄漏_Java_Android_Memory Leaks_Bluetooth - Fatal编程技术网

Java 此处理程序可能是静态的,或者蓝牙处理程序可能发生泄漏

Java 此处理程序可能是静态的,或者蓝牙处理程序可能发生泄漏,java,android,memory-leaks,bluetooth,Java,Android,Memory Leaks,Bluetooth,您好,我收到处理程序的此警告可能是静态的,或者可能发生泄漏。我曾看过其他帖子,但它并不能帮助我解决问题(警告发生在bluetoothIn的开头,一直持续到结尾 可能重复此操作。因此解决方案如下: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.bluetooth

您好,我收到处理程序的此警告可能是静态的,或者可能发生泄漏。我曾看过其他帖子,但它并不能帮助我解决问题(警告发生在bluetoothIn的开头,一直持续到结尾

可能重复此操作。因此解决方案如下:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bluetooth_datadisplay);


        txtString = (TextView) findViewById(R.id.txtString);
        txtStringLength = (TextView) findViewById(R.id.testView1);
        sensorView0 = (TextView) findViewById(R.id.sensorView0);
        sensorView1 = (TextView) findViewById(R.id.sensorView1);
        sensorView2 = (TextView) findViewById(R.id.sensorView2);
        sensorView3 = (TextView) findViewById(R.id.sensorView3);

     bluetoothIn = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == handlerState) {
                String readMessage = (String) msg.obj;
                recDataString.append(readMessage);
                int endOfLineIndex = recDataString.indexOf("~");
                if (endOfLineIndex > 0) {
                    String dataInPrint = recDataString.substring(0, endOfLineIndex);
                    txtString.setText("Data Received = " + dataInPrint);
                    int dataLength = dataInPrint.length();
                    txtStringLength.setText("String Length = " + String.valueOf(dataLength));

                    if (recDataString.charAt(0) == '#')
                    {
                        String sensor0 = recDataString.substring(1, 5);
                        String sensor1 = recDataString.substring(6, 10);
                        String sensor2 = recDataString.substring(11, 15);
                        String sensor3 = recDataString.substring(16, 20);

                        sensorView0.setText(" Sensor 0 Voltage = " + sensor0 + "V");
                        sensorView1.setText(" Sensor 1 Voltage = " + sensor1 + "V");
                        sensorView2.setText(" Sensor 2 Voltage = " + sensor2 + "V");
                        sensorView3.setText(" Sensor 3 Voltage = " + sensor3 + "V");
                    }
                    recDataString.delete(0, recDataString.length());

                }
            }
        }
    };
  }
静态类BluetoothInHandler扩展处理程序{
私人最终参考活动;
IncomingHandler(您的活动名称活动){
mActivity=新的WeakReference(活动);
}
@凌驾
公共无效handleMessage(消息消息消息)
{
final YourActivityName thizz=mActivity.get();
if(thizz==null){
返回;
}
if(msg.what==thizz.handlerState){
//做你需要的
}
}
}
可能重复此操作。因此解决方案如下:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bluetooth_datadisplay);


        txtString = (TextView) findViewById(R.id.txtString);
        txtStringLength = (TextView) findViewById(R.id.testView1);
        sensorView0 = (TextView) findViewById(R.id.sensorView0);
        sensorView1 = (TextView) findViewById(R.id.sensorView1);
        sensorView2 = (TextView) findViewById(R.id.sensorView2);
        sensorView3 = (TextView) findViewById(R.id.sensorView3);

     bluetoothIn = new Handler() {
        public void handleMessage(android.os.Message msg) {
            if (msg.what == handlerState) {
                String readMessage = (String) msg.obj;
                recDataString.append(readMessage);
                int endOfLineIndex = recDataString.indexOf("~");
                if (endOfLineIndex > 0) {
                    String dataInPrint = recDataString.substring(0, endOfLineIndex);
                    txtString.setText("Data Received = " + dataInPrint);
                    int dataLength = dataInPrint.length();
                    txtStringLength.setText("String Length = " + String.valueOf(dataLength));

                    if (recDataString.charAt(0) == '#')
                    {
                        String sensor0 = recDataString.substring(1, 5);
                        String sensor1 = recDataString.substring(6, 10);
                        String sensor2 = recDataString.substring(11, 15);
                        String sensor3 = recDataString.substring(16, 20);

                        sensorView0.setText(" Sensor 0 Voltage = " + sensor0 + "V");
                        sensorView1.setText(" Sensor 1 Voltage = " + sensor1 + "V");
                        sensorView2.setText(" Sensor 2 Voltage = " + sensor2 + "V");
                        sensorView3.setText(" Sensor 3 Voltage = " + sensor3 + "V");
                    }
                    recDataString.delete(0, recDataString.length());

                }
            }
        }
    };
  }
静态类BluetoothInHandler扩展处理程序{
私人最终参考活动;
IncomingHandler(您的活动名称活动){
mActivity=新的WeakReference(活动);
}
@凌驾
公共无效handleMessage(消息消息消息)
{
final YourActivityName thizz=mActivity.get();
if(thizz==null){
返回;
}
if(msg.what==thizz.handlerState){
//做你需要的
}
}
}

@John我试过了。它对我的案例不起作用。@John我试过了。它对我的案例不起作用。Hi@John它不起作用。oncreate块上不允许修改static。我试过了。这是内部类。所以试着将它移出
oncreate
方法。然后像
BluetoothInHandler一样在oncreate中实例化它handler=new BluetoothInHandler(this)
Hi@John。我附上了显示错误的图片。我照你说的做了,但不起作用。顺便说一句,handler(YourActivityName活动)中的这一部分传入的处理程序也用红色下划线。将
mActivity.
放在活动变量或方法之前,例如:
activity.handlerState
…让我们从这里聊天Hi@john它不起作用。oncreate块上不允许修改static。我已经尝试过了。这是内部类。因此尝试将其移出
oncreate
方法。然后在你的oncreate中引用它,比如
BluetoothInHandler=new BluetoothInHandler(this)
Hi@John。我附上了显示错误的图片。我照你说的做了,但不起作用。顺便说一句,这部分在MingHandler(YourActivityName活动)中传入的处理程序也用红色下划线。将
mActivity.
放在活动变量或方法之前,例如:
activity.handlerState
…让我们从这里开始聊天