我正在尝试使用一个Activity
在 Android 设备上启用蓝牙。以下是我扩展Activity
课程的课程。调用该方法时收到NullPointerException
错误消息。startActivityForResult()
有什么建议么?谢谢!
public class Activities extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
protected void connectBluetooth(){
Intent intentBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intentBluetooth, 0);
}
}
日志输出如下:
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): java.lang.NullPointerException
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at android.app.Activity.startActivityForResult(Activity.java:3351)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at android.app.Activity.startActivityForResult(Activity.java:3312)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at com.eyesore.bluetooth.Activities.connectBluetooth(Activities.java:28)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at com.eyesore.bluetooth.BluetoothModule.example(BluetoothModule.java:77)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:60)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:636)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:831)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:307)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at android.os.Handler.dispatchMessage(Handler.java:95)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at android.os.Looper.loop(Looper.java:137)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15246 W/System.err ]
?:??: W/?(?): at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:104)
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15231 E/TiJSError ]
?:??: W/?(?): (main) [6,293329] ----- Titanium Javascript Runtime Error -----
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15231 E/TiJSError ]
?:??: W/?(?): (main) [0,293329] - In app.js:71,12
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15231 E/TiJSError ]
?:??: W/?(?): (main) [0,293329] - Message: Uncaught Error: Java Exception occurred
?:??: W/?(?): [ 09-09 18:08:38.497 15231:15231 E/TiJSError ]
?:??: W/?(?): (main) [0,293329] - Source: bluetooth.example();
?:??: W/?(?): [ 09-09 18:08:38.517 15231:15246 E/V8Exception ]
?:??: W/?(?): Exception occurred at app.js:71: Uncaught Error: Java Exception occurred
下面的清单文件 -
<manifest>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.bluetooth.adapter.action.REQUEST_ENABLE"/>
<application>
<activity android:name=".Activities" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>