1

MUPDF リーダーを使用して、アプリで PDF リーダーのレンダリングに取り組んでいます。レンダリング中に nullpointer エラーがスローされます。コードを完全に添付しました。SD カードに PDF があり、SD カードがマウント可能かどうかを確認しました。助けてください

マニフェスト.xml

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ebookr"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission
     android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity android:name="com.artifex.mupdfdemo.MuPDFActivity" 
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/vnd.ms-xpsdocument"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/pdf"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/x-cbz"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.xps"/>
            <data android:host="*"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.pdf"/>
            <data android:host="*"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.cbz"/>
            <data android:host="*"/>
        </intent-filter>
    </activity>
    <activity android:name="OutlineActivity"
              android:label="@string/outline_title">
    </activity>

    <activity
        android:name="com.example.ebookr.MainActivity"
        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>

ManiActivity.java

package com.example.ebookr;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.res.AssetManager;
import android.util.Log;
import android.view.Menu;
import com.artifex.mupdfdemo.*;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CopyAssetsbrochure(); 

    try
    {
    //Uri uri = Uri.parse("/sdcard/divya.pdf");

    String path = "/sdcard/divya.pdf";
    MuPDFActivity pdf = new MuPDFActivity(); 
    try {
    pdf.openFileInput(path);
    }
    catch(Exception e)
    {
        Log.e("in code",e.getMessage());
    }

    /*Intent intent = new Intent(getBaseContext(), MuPDFActivity.class);

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    intent.setAction(Intent.ACTION_VIEW);

    intent.setData(uri);

    getBaseContext().startActivity(intent); */
    }
    catch (Exception e) {
        // TODO Auto-generated catch block
        StackTraceElement[] stack = e.getStackTrace();
        String StringTrace = "";
        String Trace = null;
        for(StackTraceElement line : stack)
        {
           Trace += line.toString();
        }

            Log.e("Soap",Trace);

        String err = (e.getMessage()==null)?"SD Card failed":e.getMessage();
        Log.e("sdcard-err2:",err);  
        e.getCause();

    } 



}

private void CopyAssetsbrochure() {
    AssetManager assetManager = getAssets();
    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_MOUNTED.equals(state)) {
        Log.d("Test", "sdcard mounted and writable");
    }
    else
    {
        Log.d("Test", "sdcard state: " + state);
    }
    String[] files = null;
    try 
    {
        files = assetManager.list("");
    } 
    catch (IOException e)
    {
        Log.e("tag", e.getMessage());
    }
    for(int i=0; i<files.length; i++)
    {
        String fStr = files[i];
        if(fStr.equalsIgnoreCase("divya.pdf"))
        {
            InputStream in = null;
            OutputStream out = null;
            try 
            {
              in = assetManager.open(files[i]);
              out = new FileOutputStream("/sdcard/" + files[i]);
              copyFile(in, out);
              in.close();
              in = null;
              out.flush();
              out.close();
              out = null;
              break;
            } 
            catch(Exception e)
            {
                Log.e("CopyAssests", e.getMessage());
            } 
        }
    }
}

 private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while((read = in.read(buffer)) != -1){
      out.write(buffer, 0, read);
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

LogCat:

07-07 11:22:49.689: W/Trace(2085): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:21.929: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:21.929: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:21.939: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0   
07-07 11:23:22.310: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:22.365: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:23.279: D/Test(2189): sdcard mounted and writable
07-07 11:23:24.631: E/Soap(2189): nullandroid.util.Log.println_native(Native                    Method)android.util.Log.e(Log.java:231)com.example.ebookr.MainActivity.onCreate(MainActivity.java:40)android.app.Activity.performCreate(Activity.java:5104)android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)android.app.ActivityThread.access$600(ActivityThread.java:141)android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)android.os.Handler.dispatchMessage(Handler.java:99)android.os.Looper.loop(Looper.java:137)android.app.ActivityThread.main(ActivityThread.java:5039)java.lang.reflect.Method.invokeNative(Native Method)java.lang.reflect.Method.invoke(Method.java:511)com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)dalvik.system.NativeStart.main(Native Method)
07-07 11:23:24.631: E/sdcard-err2:(2189): println needs a message
07-07 11:23:24.769: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:24.790: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:24.861: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:24.909: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.099: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.109: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.139: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.209: I/Choreographer(2189): Skipped 31 frames!  The application may be doing too much work on its main thread.
07-07 11:23:25.249: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.249: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.269: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.269: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.279: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.279: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.299: D/gralloc_goldfish(2189): Emulator without GPU emulation detected.
07-07 11:23:25.409: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
07-07 11:23:25.469: W/Trace(2189): Unexpected value from nativeGetEnabledTags: 0
4

1 に答える 1