0

I am using iTextG for an android application. My objective is to read from an existing pdf file for later manipulations etc. I want to read a file called "Chemistry.pdf" which I have placed in my assets folder. I am using the following code to (try to) read the pdf

        AssetManager assetManager = getAssets();
        InputStream istr = null;

    try
            {
            istr =(InputStream) assetManager.open("Chemistry.pdf");         
                Log.d("OK", "done");
            }
            catch (FileNotFoundException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

when I execute the code, the app crashes. if assets doesnt work, where should I include the pdf file(inside the app) ? What is going wrong ?

P.S. I get these error (there are 11 more)

03-28 15:28:52.455: E/AndroidRuntime(918): FATAL EXCEPTION: main 03-28 15:28:52.455: E/AndroidRuntime(918): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.teest/com.example.teest.MainActivity}: java.lang.ClassCastException: android.content.res.AssetManager$AssetInputStream cannot be cast to com.itextpdf.text.pdf.codec.Base64$InputStream 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread.access$600(ActivityThread.java:141) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.os.Handler.dispatchMessage(Handler.java:99) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.os.Looper.loop(Looper.java:137) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread.main(ActivityThread.java:5039) 03-28 15:28:52.455: E/AndroidRuntime(918): at java.lang.reflect.Method.invokeNative(Native Method) 03-28 15:28:52.455: E/AndroidRuntime(918): at java.lang.reflect.Method.invoke(Method.java:511) 03-28 15:28:52.455: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 03-28 15:28:52.455: E/AndroidRuntime(918): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 03-28 15:28:52.455: E/AndroidRuntime(918): at dalvik.system.NativeStart.main(Native Method) 03-28 15:28:52.455: E/AndroidRuntime(918): Caused by: java.lang.ClassCastException: android.content.res.AssetManager$AssetInputStream cannot be cast to com.itextpdf.text.pdf.codec.Base64$InputStream 03-28 15:28:52.455: E/AndroidRuntime(918): at com.example.teest.MainActivity.onCreate(MainActivity.java:30) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.Activity.performCreate(Activity.java:5104) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 03-28 15:28:52.455: E/AndroidRuntime(918): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

SOLVED: The error was caused due to an unintialized variable.

harveyslash
  • 5,906
  • 12
  • 58
  • 111

0 Answers0