近くのBluetoothデバイスに接続する&を発見するこのアプリを開発しようとしています。私はNULLPOINTEREXCEPTIONにどこで私のアプリがクラッシュした。私のUUIDには何の価値も割り当てられていないためだと分かった。今、私はAndroid開発の新品です&私のUUIDに割り当てられる値がわからないので、クラッシュしません。私のアプリが必要とするUUIDを知る方法?
私のConnectedBTDevice.javaは、他のBluetoothデバイスへの接続を処理します。
package vertex2016.mvjce.edu.bluealert;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.io.IOException;
import java.util.UUID;
public class ConnectedBTDevice extends AppCompatActivity {
public BluetoothDevice btd;
public BluetoothSocket btSocket, tempSocket;
private UUID myUUID;
ArrayAdapter arr;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_connected_btdevice);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
arr = new ArrayAdapter(this, android.R.layout.simple_list_item_2);
btd = getIntent().getParcelableExtra("BluetoothDevice");
connectBT();
displayStuff();
}
public void connectBT() {
Thread myThread = new Thread() {
public void run() {
tempSocket = null;
btSocket = null;
try {
tempSocket = btd.createRfcommSocketToServiceRecord(myUUID);
} catch (IOException e) {
e.printStackTrace();
}
BluetoothAdapter.getDefaultAdapter().cancelDiscovery();
try {
tempSocket.connect();
arr.add("CONNECTED TO-->" + btd.getName());
} catch (IOException e) {
e.printStackTrace();
try {
tempSocket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
};
myThread.start();
}
public void displayStuff()
{
lv = (ListView)findViewById(R.id.connectedBTlistView);
lv.setAdapter(arr);
}
}
そして、これは私の質問がある
03-24 00:32:11.254 5772-5772/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_idle id: [email protected] time:66442377
03-24 00:32:11.594 5772-5772/vertex2016.mvjce.edu.bluealert E/ActivityThread: Performing stop of activity that is not resumed: {vertex2016.mvjce.edu.bluealert/vertex2016.mvjce.edu.bluealert.MainActivity}
java.lang.RuntimeException: Performing stop of activity that is not resumed: {vertex2016.mvjce.edu.bluealert/vertex2016.mvjce.edu.bluealert.MainActivity}
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3377)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3458)
at android.app.ActivityThread.access$1200(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
03-24 00:32:16.677 5772-5772/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_idle id: [email protected] time:66447800
03-24 00:32:17.811 5772-8519/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_launch_request id:vertex2016.mvjce.edu.bluealert time:66448935
03-24 00:32:18.420 5772-5772/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_idle id: [email protected] time:66449543
03-24 00:32:24.308 5772-5772/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_launch_request id:vertex2016.mvjce.edu.bluealert time:66455431
03-24 00:32:24.593 5772-9062/vertex2016.mvjce.edu.bluealert W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
03-24 00:32:24.611 5772-9062/vertex2016.mvjce.edu.bluealert E/AndroidRuntime: FATAL EXCEPTION: Thread-39196
Process: vertex2016.mvjce.edu.bluealert, PID: 5772
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.util.UUID.getMostSignificantBits()' on a null object reference
at android.os.ParcelUuid.writeToParcel(ParcelUuid.java:129)
at android.bluetooth.IBluetooth$Stub$Proxy.connectSocket(IBluetooth.java:1767)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:309)
at vertex2016.mvjce.edu.bluealert.ConnectedBTDevice$1.run(ConnectedBTDevice.java:63)
03-24 00:32:25.172 5772-5772/vertex2016.mvjce.edu.bluealert I/Timeline: Timeline: Activity_idle id: [email protected] time:66456295
03-24 00:32:25.945 5772-9062/vertex2016.mvjce.edu.bluealert I/Process: Sending signal. PID: 5772 SIG: 9
エラーを示しlogcatです:私はそれは私がしたい任意のデバイスに接続するようmyUUIDする値を割り当てていますか?この質問がばかげていると申し訳ありませんが、私は本当にUUIDがどのような役割を果たしているのかを明確に把握しようとしています(どの値を割り当てるのかなど)。&
私はAndroid: How do bluetooth UUIDs work?のような投稿を行っていますが、主な質問には答えていないようです。私のUUIDにはどのような価値がありますか?
ありがとうございました!
[Android:Bluetooth UUIDはどのように機能するのですか?](0120-18753) –
「あなたはどのような価値を持っていますか?私が欲しいどんなデバイスにも接続できるようにmyUUIDに割り当てるのですか?私が会うすべての人と話をして、それらを「ボブ」と呼んでいると言っているようなものです。 UUIDは、あなたが話しているデバイス/アプリケーションを識別するために使用する名前です。あなたが通信しようとしているデバイスのUUIDを取得する方法は、製造元に依頼して(またはそれが何であるかを知るためにリバースエンジニアリング技術を試して)かどうかによって異なります。 –
これは単純化されています。 http://developer.android.com/guide/topics/connectivity/bluetooth.html、特にhttp://developer.android.com/guide/topics/connectivity/bluetooth.html#ConnectingDevicesをご覧ください。 –