如何在android中解决此Windows管理器错误?
我无法理解代码在这里究竟发生了什么。 我的代码有时运行良好,有时运行不正常 我正在创建蓝牙连接。单击搜索按钮时,我正在搜索设备。它给了我设备列表,我正在listview上显示它。这一切都很好 现在在listItem上单击,我想将我的设备与列表中选定的设备配对。 我用这个代码来做这件事如何在android中解决此Windows管理器错误?,android,bluetooth,Android,Bluetooth,我无法理解代码在这里究竟发生了什么。 我的代码有时运行良好,有时运行不正常 我正在创建蓝牙连接。单击搜索按钮时,我正在搜索设备。它给了我设备列表,我正在listview上显示它。这一切都很好 现在在listItem上单击,我想将我的设备与列表中选定的设备配对。 我用这个代码来做这件事 listViewDetected.setOnItemClickListener(new OnItemClickListener() { @Override pu
listViewDetected.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
Log.i("Log", "ListItem is clicked at :"+position);
posn = position;
String str = (String) listViewDetected.getItemAtPosition(position);
Log.i("Log", "ListItem is :"+str);
bluetoothDevice=arrayListBluetoothDevices.get(position);
final BluetoothDevice device = arrayListBluetoothDevices.get(position);
Log.i("Log", "UUID string is :"+uid);
new Thread() {
public void run() {
connect(device);
};
}.start();
}
private void connect(BluetoothDevice bluetoothDevicess) {
// TODO Auto-generated method stub
Log.i("Log", "connect method after click: ");
ParcelUuid[] uuids = servicesFromDevice(bluetoothDevicess);
adapterPaired.notifyDataSetChanged();
Log.i("Log", "service method executed");
}
});
public ParcelUuid[] servicesFromDevice(BluetoothDevice device) {
try {
Log.i("Log", "service method is called ");
Class cl = Class.forName("android.bluetooth.BluetoothDevice");
Class[] par = {};
Method method = cl.getMethod("createBond", par);
Object[] args = {};
ParcelUuid[] retval = (ParcelUuid[]) method.invoke(device, args);
if(retval==null)
{
Log.i("Log", "GOT the Array as null:");
}
else
{
Log.i("Log", "GOT the Array:"+retval.length);
}
/* for(int i = 0;i<retval.length;i++)
{ Log.i("Log", "GOT : "+retval[i]);
}*/
return retval;
} catch (Exception e) {
Log.i("Log", "Inside catch of serviceFromDevice Method");
e.printStackTrace();
return null;
}
}
我找到了这个问题的解决办法。这是因为Brodcast接收器的缘故。我当时正在点击列表项,同时我的接收器被触发。在这一点上,我调用了线程对象。所以,有时候,如果我的线程没有被调用,那么listitem单击工作正常。谢谢你的朋友们。谢谢。您在上面发布的问题代码中是否有错误。实际上,我正在处理单击列表项的所有配对工作。但是当我单击时,void click()方法中甚至没有一个日志正在打印。我在我发布的logcat上得到了上面的消息,你发布的日志中的错误行在哪里!?,请把它贴出来。它什么时候工作得很好,什么时候不好?我认为简单的张贴代码没有任何警告和错误!因为它很简单,基本上是代码!请参阅编辑的代码。请告诉我这里发生了什么。我无法理解为什么它有时会运行,为什么不运行。
09-01 16:17:26.405: I/KeyInputQueue(171): Enqueueing touch event0
09-01 16:17:26.405: I/WindowManager(171): Read next event 0
09-01 16:17:26.405: I/WindowManager(171): Delivering pointer 0 > Window{4a6ea918 com.bdm/com.bdm.BluetoothDemo paused=false}
09-01 16:17:26.515: I/KeyInputQueue(171): Enqueueing touch event1
09-01 16:17:26.515: I/WindowManager(171): Read next event 1
09-01 16:17:26.515: I/WindowManager(171): Delivering pointer 1 > Window{4a6ea918 com.bdm/com.bdm.BluetoothDemo paused=false}