Android应用程序在启动第二个活动之前崩溃

时间:2015-10-11 16:43:56

标签: android arduino

嘿伙计们我很久以前就试图修复它我在寻求帮助之前放弃它...我不知道处理程序有什么问题...我正在尝试从arduino向android发送一些整数。 。

ARDUINO草图:

  void sendAndroidValues()
 {
  //puts # before the values so app knows what to do with the data
  Serial.print('#');
  //for loop cycles through 4 sensors and sends values via serial
  Serial.print(digitalRead(5));
    Serial.print('+');
    //technically not needed but I prefer to break up data values
 Serial.print('~'); //used as an end of transmission character - used in app for string length
 Serial.println();
 delay(1000);        //added a delay to eliminate missed transmissions
}

ANDROID

private OnItemClickListener mDeviceClickListener = new OnItemClickListener() {
    public void onItemClick(AdapterView<?> av, View v, int arg2, long arg3) {

        textView1.setText("Connecting...");
        // Get the device MAC address, which is the last 17 chars in the
        // View
        String info = ((TextView) v).getText().toString();
        String address = info.substring(info.length() - 17);

        Intent i = new Intent(DeviceListActivity.this, MainActivity.class);
        i.putExtra(EXTRA_DEVICE_ADDRESS, address);
        startActivity(i);
    }
};

在开始之前崩溃的活动......任何帮助都将在此之前提前感谢。

    public void run() {
        Toast.makeText(getBaseContext(), "run()---before",
                Toast.LENGTH_LONG).show();
        byte[] buffer = new byte[256];
        int bytes;

        // Keep looping to listen for received messages
        while (true) {
            Toast.makeText(getBaseContext(), "while true",
                    Toast.LENGTH_LONG).show();
            try {
                Toast.makeText(getBaseContext(), "in try",
                        Toast.LENGTH_LONG).show();
                bytes = mmInStream.read(buffer); // read bytes from input
                                                    // buffer
                String readMessage = new String(buffer, 0, bytes); // Send
                                                                    // the
                // obtained bytes to the UI Activity via handler
                bluetoothIn.obtainMessage(handlerState, bytes, -1,
                        readMessage).sendToTarget();
                Toast.makeText(getBaseContext(), "listner noonononononononononon",
                        Toast.LENGTH_LONG).show();
            } catch (IOException e) {
                Toast.makeText(getBaseContext(), "listner eror",
                        Toast.LENGTH_LONG).show();

                 break;
            }
        }
    }

0 个答案:

没有答案