1

I have tried to integrate this PDF Viever, and i am getting this crash message:

05-31 11:20:48.717: D/ddm-heap(235): Got feature list request

05-31 11:21:16.117: D/dalvikvm(235): newInstance failed: p0 i0 [0 a1

05-31 11:21:16.127: D/AndroidRuntime(235): Shutting down VM

05-31 11:21:16.127: W/dalvikvm(235): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

05-31 11:21:16.127: E/AndroidRuntime(235): Uncaught handler: thread main exiting due to uncaught exception

05-31 11:21:16.137: E/AndroidRuntime(235): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{net.sf.andpdf.pdfviewer/net.sf.andpdf.pdfviewer.PdfViewerActivity}: 
java.lang.InstantiationException: net.sf.andpdf.pdfviewer.PdfViewerActivity

05-31 11:21:16.137: E/AndroidRuntime(235):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)

This is what i try to implement : https://github.com/jblough/Android-Pdf-Viewer-Library

The help text for integrating the activity says:

1) Add PdfViewer.jar into your project's build path

2) Copy the following drawable resources from PdfViewer/res/drawable into YourProject/res/drawable
     left_arrow.png
     right_arrow.png
     zoom_in.png
     zoom_out.png

3) Copy the following layout resources from PdfViewer/res/layout into YourProject/res/layout
     dialog_pagenumber.xml
     pdf_file_password.xml

!!THIS IS WHERE THE PROBLEM LIES!! - SE BELOW

4) ***Derive your PDF activity from net.sf.andpdf.pdfviewer.PdfViewerActivity***

5) Using the default drawables and layouts:
     public int getPreviousPageImageResource() { return R.drawable.left_arrow; }
     public int getNextPageImageResource() { return R.drawable.right_arrow; }
     public int getZoomInImageResource() { return R.drawable.zoom_in; }
     public int getZoomOutImageResource() { return R.drawable.zoom_out; }
     public int getPdfPasswordLayoutResource() { return R.layout.pdf_file_password; }
     public int getPdfPageNumberResource() { return R.layout.dialog_pagenumber; }
     public int getPdfPasswordEditField() { return R.id.etPassword; }
     public int getPdfPasswordOkButton() { return R.id.btOK; }
     public int getPdfPasswordExitButton() { return R.id.btExit; }
     public int getPdfPageNumberEditField() { return R.id.pagenum_edit; }

6) Invoke your PdfViewActivity derived with the following code:
     Intent intent = new Intent(this, YourPdfViewerActivity.class);
     intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");
     startActivity(intent);

I have tried integrating the pdfviewer activity .jar both as External JAR or implementing it in the assets folder and loading the Jar from there. The PdfViewer activity is in the src class folder (sf.net.andpdf.....), which i have also named 100% like the code was "created".

Manifest:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".Niels"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <activity android:name=".PdfViewerActivity" android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.PDFVIEWERACTIVITY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
     </activity>        
    <activity android:name=".PdfViewerActivity" />               
</application>

Niels.Java:

    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1 : 

            try{    
        Intent intent = new Intent(this, PdfViewerActivity.class /*i called this without "Your" as the actual class is named without "Your"*/ );
         intent.putExtra(net.sf.andpdf.pdfviewer.PdfViewerActivity.EXTRA_PDFFILENAME, "R.drawable.untitled" /*-> untitled.pdf*/);
         startActivity(intent); }
            catch (Exception e){                        
            e.printStackTrace();
            }

So any ideas of what i am doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Niels
  • 635
  • 3
  • 9
  • 23
  • The `java.lang.InstantiationException` seems to imply that they meant **business** with bullet #4, "Derive your PDF activity from net.sf.andpdf.pdfviewer.PdfViewerActivity" - it's thrown because the class you tried to create is **abstract**.You should make a subclass of this `Activity` and add that to your AndroidManifest.xml instead. – Jens May 31 '12 at 11:39
  • Yes, i had a feeling i did not read that part correctly. – Niels May 31 '12 at 15:08
  • I have made an update because i now have a problem with "unable to resolve superclass..." – Niels May 31 '12 at 16:33
  • That sounds like you've got a case of the ["ADT17"](http://stackoverflow.com/questions/9846586/libraries-in-sdk-17-android) - since you're importing a .jar. I'm guessing it "looks good in Eclipse" but dies horribly when running? – Jens May 31 '12 at 21:16
  • Please don't substantially edit a question once it has been asked, other than to improve it in its current form. When new readers approach your question, they should see the question as it was asked - and if you have a follow up question, ask it in the comments (if it is trivial) or ask a new question (if it is substantial, as here). – halfer May 31 '12 at 21:50
  • Post Script: if you solve a problem yourself, add a solution in the answer box, and _not_ in the question itself. This helps readers differentiate what part is the question, and (if applicable) what part is the answer. If you have a solution to your first problem, add it below and transfer your supplementary question to a new question `:)`. – halfer May 31 '12 at 21:52
  • Hi Jens. I got ADT18. I did see that ADT17 issue from different places, so i have tried setting the .jar file in libs / assets / importing it as external and setting it from inside the package. Inside eclipse it does look "perfect". The problem is when i hit the button1.. . If i hit button2, it does what is intended.. :-P ,,, Is there a .jar import example which can be used to test if the way i am working is right.. ? – Niels May 31 '12 at 21:59
  • Halfer - I guess this is how you want the thing done :-) ? – Niels May 31 '12 at 22:22
  • @Niels - much better, thanks & undownvoted. I've removed 'answer below' as that's the usual format here, and the code blocks and help file I've `quoted`. – halfer Jun 01 '12 at 09:22

1 Answers1

1

OK, the problem was a missing instatiation of the pdfactivity.

I created new class :

PdfReader.java :

package net.sf.andpdf.pdfviewer;

public class PdfReader extends PdfViewerActivity {
@Override
public int getPreviousPageImageResource() {
    // TODO Auto-generated method stub
    return 0;
}

because of this i changed this section :

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.button1 : 
        try {   
            Intent intent = new Intent(this, PdfReader.class /*the name changed*/);
            intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "R.drawable.untitled");
            startActivity(intent); 
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

and lastly i added the new activity to the manifest as well.

This solved this problem, i though got a new problem with "unable to resolve superclass" - which is going into a new question.

Botz3000
  • 39,020
  • 8
  • 103
  • 127
Niels
  • 635
  • 3
  • 9
  • 23