Activity
AndroidデバイスでBluetoothを有効にするためにを利用しようとしています。以下は私がクラスを拡張した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>