Android Logcat error

2019-07-31 17:45发布

问题:

Anyone can tell me what's the reason behind this run-time error?

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo Caused by: java.lang.InstantiationException

i'm trying to make a PDF reader app following Joe Blough's Android PDF Viewer library at GitHub: https://github.com/jblough/Android-Pdf-Viewer-Library. I followed everything and I end up with this error.

12-20 03:43:14.037: E/AndroidRuntime(29822): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.traininghandouts.app/com.traininghandouts.app.PdfViewer}: java.lang.InstantiationException: com.traininghandouts.app.PdfViewer
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.os.Handler.dispatchMessage(Handler.java:99)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.os.Looper.loop(Looper.java:123)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread.main(ActivityThread.java:4627)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at java.lang.reflect.Method.invokeNative(Native Method)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at java.lang.reflect.Method.invoke(Method.java:521)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at dalvik.system.NativeStart.main(Native Method)
12-20 03:43:14.037: E/AndroidRuntime(29822): Caused by: java.lang.InstantiationException: com.traininghandouts.app.PdfViewer
12-20 03:43:14.037: E/AndroidRuntime(29822):    at java.lang.Class.newInstanceImpl(Native Method)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at java.lang.Class.newInstance(Class.java:1429)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-20 03:43:14.037: E/AndroidRuntime(29822):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-20 03:43:14.037: E/AndroidRuntime(29822):    ... 11 more

here's my code:

try{
  String path =  "mnt/sdcard/android-android-ui-design-patterns.pdf";

  Intent intent = new Intent(this, PdfViewer.class);
  intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
  startActivity(intent);


}catch(Exception e){
   e.printStackTrace();
}

回答1:

InstantiationException:

Thrown when a program attempts to access a constructor which is not accessible from the location where the reference is made.

That came from The Docs

I can't say what EXACTLY caused your exception, but if you post the entirety of the error from Logcat and the line where the exception happens, or a block of code where the exception happens, that may help a little more.