简体   繁体   English

Android ClassNotFoundException运行时错误

[英]Android ClassNotFoundException error at runtime

I am developing an app in Android Studio. 我正在Android Studio中开发应用程序。 The package name is com.mycompany.myapp . 程序包名称为com.mycompany.myapp。 Then, I want to reuse some codes from another package : com.theta360.sample.v2 . 然后,我想重用另一个包com.theta360.sample.v2中的一些代码。

To do this, I added a package named "com.theta360.sample.v2" in Android studio. 为此,我在Android Studio中添加了一个名为“ com.theta360.sample.v2”的程序包。 And then, I simply copied the src directory of com.theta360.sample.v2 to project/app/src/main/, which also includes mycompany/myapp . 然后,我只是将com.theta360.sample.v2的src目录复制到project / app / src / main /,其中还包括mycompany / myapp。

In MainActivity.java. 在MainActivity.java中。 I need to use class LogView from theta360.sample.v2. 我需要使用theta360.sample.v2中的LogView类。 So, added "import com.theta360.sample.v2.view.LogView". 因此,添加了“ import com.theta360.sample.v2.view.LogView”。

Then, I successfully build the app. 然后,我成功构建了该应用程序。

However, when I launched the app on device, I received error with message: 但是,当我在设备上启动该应用程序时,收到错误消息:

..Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.LogView" on path: DexPathList... ..原因:java.lang.ClassNotFoundException:在路径:DexPathList上找不到类“ android.view.LogView”。

My questions are: 我的问题是:

(1) why at run-time, the system try to look for android.view.LogView; (1)为什么在运行时,系统尝试寻找android.view.LogView; LogView is from com.theta360.sample.v2.view . LogView来自com.theta360.sample.v2.view。 How to fix it? 如何解决?

(2) What's the correct way to use another package with source. (2)将另一个软件包与源一起使用的正确方法是什么? Can I simply copy the codes as I did above? 我可以像上面一样简单地复制代码吗?

I have solved my own question. 我已经解决了我自己的问题。 The error is caused by LogView used in the layout xml. 该错误是由布局xml中使用的LogView引起的。 It should be changed to a name with it's package prefix. 应该将其更改为带有程序包前缀的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM