[英]At first install the app crashes, but after reinstall it works
I have never met so strange issue so far.到目前为止,我从未遇到过如此奇怪的问题。 The app compiles fine.
该应用程序编译良好。 But at first run it crashes on the test device, but if the project is cleaned and re-run the app works fine.
但是在第一次运行时它会在测试设备上崩溃,但是如果项目被清理并重新运行,应用程序可以正常工作。 If I try to install the apk the result is the same: installing the app crashes but after reinstalling it runs fine.
如果我尝试安装 apk,结果是一样的:安装应用程序崩溃,但重新安装后它运行良好。
The issue is happening on all of my test devices and under Eclipss and Android Studio.这个问题发生在我所有的测试设备上以及 Eclipss 和 Android Studio 下。 I spent many hours to find a similar case but no avail.
我花了很多时间找到一个类似的案例,但无济于事。 The previous version of the app worked fine, but if I revert the files to an earlier version the issue remains.
该应用程序的先前版本运行良好,但如果我将文件恢复到较早版本,问题仍然存在。
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
My guess something went wrong with project set up but could not find the culprit.我猜项目设置出了问题,但找不到罪魁祸首。 Deleting the bin folder, making countless project cleaning and restarts did not lead anywhere ...
删除bin文件夹,进行无数项目清理和重启并没有导致任何结果......
The full stack trace:完整的堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.plexnor.android.good/com.plexnor.android.good.CaptureActivity}: android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2425)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
... 11 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
... 22 more
android.view.InflateException: Binary XML file line #17: Error inflating class com.plexnor.android.good.ViewfinderView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
... 22 more
java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView" on path: DexPathList[[zip file "/data/app/com.plexnor.android.good-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.plexnor.android.good-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:565)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
at android.view.LayoutInflater.inflate(LayoutInflater.java:463)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:359)
at android.app.Activity.setContentView(Activity.java:2010)
at com.plexnor.android.good.CaptureActivity.onCreate(SourceFile:317)
at android.app.Activity.performCreate(Activity.java:5426)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:171)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1297)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5506)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
EDIT 1: The app crashes earlier even entering the main activity when processing the layout.编辑 1:即使在处理布局时进入主要活动,应用程序也会更早崩溃。 The beginning of the layout:
布局的开始:
<?xml version="1.0" encoding="UTF-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<SurfaceView
android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="@+id/relative_layout_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="0dp"
android:layout_marginTop="0dp" >
<RelativeLayout
android:id="@+id/learning_swipe_relative_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent" >
<ImageView
android:id="@+id/learningSwipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:padding="30dp"
android:src="@drawable/swipe" />
</RelativeLayout>
<com.plexnor.android.good.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RelativeLayout
android:id="@+id/learning_relative_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@android:color/transparent" >
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.plexnor.android.good.ViewfinderView"
引起:java.lang.ClassNotFoundException:没有找到类“com.plexnor.android.good.ViewfinderView”
ClassNotFoundException in Java is a subclass of java.lang.Exception and Comes when Java Virtual Machine tries to load a particular class and doesn't found the requested class in classpath. Java 中的ClassNotFoundException是java.lang.Exception的子类,当 Java 虚拟机尝试加载特定类但在类路径中未找到请求的类时出现。
Another important point about this Exception is that, It is a checked Exception and you need to provide explicitly Exception handling while using methods which can possibly throw classnotfoundexception in java either by using try-catch block or by using throws
clause.关于此异常的另一个重点是,它是一个已检查的异常,您需要在使用可能在 java 中通过
try-catch block or by using throws
子句抛出classnotfoundexception 的方法时提供显式异常处理。
Check whether your classpath contains that jar, if your classpath doesn't contain the jar then just add that class in your classpath.
检查您的类路径是否包含该 jar,如果您的类路径不包含该 jar,则只需将该类添加到您的类路径中。
Because I could not solve the issue I suspended that project for some months.因为我无法解决这个问题,所以我暂停了这个项目几个月。 Using Eclipse in my another project the same issue emerged after including a third party SDK to the project.
在我的另一个项目中使用 Eclipse 后,在项目中包含第三方 SDK 后出现了同样的问题。 Cleaning project, changing things in build path did not help.
清理项目,更改构建路径中的内容无济于事。 So, I cloned the project to a new workspace and added the SDK ... and it worked that way.
所以,我将项目克隆到一个新的工作区并添加了 SDK ......它以这种方式工作。 After trying out the old abandoned project it worked out of the box.
在尝试了旧的废弃项目后,它开箱即用。 Thus I think the issue caused by a bug in the development environment.
因此我认为问题是由开发环境中的错误引起的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.