デバイスにpdfreaderがある場合は、rawフォルダーからpdfファイルを読み取りたいです。コードは次のとおりです。
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("android.resource://com.powergroupbd.pdfreader/raw" + R.raw.androidtasksmwp));
intent.setType("application/pdf");
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
if (activities.size() > 0) {
startActivity(intent);
} else {
Toast.makeText(getApplicationContext(), "No pdfreader found", Toast.LENGTH_LONG).show();
}
しかし、このプロジェクトを実行すると、エラーが表示されます。logcatの結果は次のとおりです。
06-21 02:05:04.408: W/dalvikvm(7763): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-21 02:05:04.418: E/AndroidRuntime(7763): FATAL EXCEPTION: main
06-21 02:05:04.418: E/AndroidRuntime(7763): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.qo.android.htcgep/com.qo.android.am.pdflib.app.RenderScreen}: java.lang.NullPointerException
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.os.Looper.loop(Looper.java:130)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-21 02:05:04.418: E/AndroidRuntime(7763): at java.lang.reflect.Method.invokeNative(Native Method)
06-21 02:05:04.418: E/AndroidRuntime(7763): at java.lang.reflect.Method.invoke(Method.java:507)
06-21 02:05:04.418: E/AndroidRuntime(7763): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-21 02:05:04.418: E/AndroidRuntime(7763): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-21 02:05:04.418: E/AndroidRuntime(7763): at dalvik.system.NativeStart.main(Native Method)
06-21 02:05:04.418: E/AndroidRuntime(7763): Caused by: java.lang.NullPointerException
06-21 02:05:04.418: E/AndroidRuntime(7763): at com.qo.android.am.pdflib.app.RenderScreen.onNewIntent(Unknown Source)
06-21 02:05:04.418: E/AndroidRuntime(7763): at com.qo.android.am.pdflib.app.RenderScreen.onCreate(Unknown Source)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-21 02:05:04.418: E/AndroidRuntime(7763): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-21 02:05:04.418: E/AndroidRuntime(7763): ... 11 more
06-21 02:05:04.418: W/ActivityManager(96): Force finishing activity com.qo.android.htcgep/com.qo.android.am.pdflib.app.RenderScreen
私は何を間違っていますか?助けてください..:(