简体   繁体   English

OrmliteSqliteOpenHelper的NoClassDefFound错误

[英]NoClassDefFound error with OrmliteSqliteOpenHelper

I have a class which extends OrmliteSqliteOpenHelper in order to provide a persistence module for an Android application. 我有一个扩展OrmliteSqliteOpenHelper的类,以便为Android应用程序提供一个持久性模块。 The problem is, whenever I access this class from the test project in Eclipse, it throws a NoClassDefFound Exception. 问题是,每当我从Eclipse中的测试项目访问此类时,它都会引发NoClassDefFound异常。 The source code appears to be fine as the package is imported and Eclipse has no highlighting to indicate anything will go wrong, but it does. 源代码似乎很好,因为导入了该软件包,并且Eclipse没有突出显示任何东西都会出问题,但是确实如此。

Here's the kicker: not only does everything else in the project work fine when accessed from the test project, but when I move this file into the test project voila it works perfectly! 这是一个关键:从测试项目中访问项目时,项目中的其他所有功能不仅可以正常工作,而且当我将此文件移动到测试项目中时,它也可以完美运行! The issue is that it needs to be in the actual project in order for other components to make calls to it. 问题在于,它必须位于实际项目中,以便其他组件对其进行调用。 Has anyone ever encountered this error or have any idea where I might be going wrong? 有没有人遇到此错误,或者有任何想法我可能会出错?

The class path is set correctly as all the other classes work and the test project always has the main project added to its class path. 当所有其他类都起作用时,将正确设置类路径,并且测试项目始终将主项目添加到其类路径中。 I also tried moving the OrmliteSqliteOpenHelper object to an inner class: this allowed the outer class to be visible and touched but as soon as it tried to instantiate the inner class the same error occurs. 我还尝试将OrmliteSqliteOpenHelper对象移动到内部类:这样可以使外部类可见和被触摸,但是一旦尝试实例化内部类,就会发生相同的错误。 Also, if I copy this file into both projects in the same package, an error occurs stating "class ref in pre-verified class resolved to unexpected implementation" whenever something in the main project tries to access this class. 同样,如果我将此文件复制到同一程序包中的两个项目中,则每当主项目中的某人尝试访问该类时,就会出现错误,指出“预验证的类中的类ref被解析为意外的实现”。 Clearly, there is some difference in the way the class is being compiled/handled between the two projects. 显然,两个项目之间类的编译/处理方式有所不同。

I'm quite stumped :/ Thanks a ton for any assistance! 我很沮丧:/感谢您的协助!

Well friends, I seem to have hacked together a solution for this issue: I linked the entire 'src' folder from the main project into the one for the test project. 好朋友,我似乎已经找到了解决该问题的解决方案:我将整个主项目中的整个“ src”文件夹链接到了测试项目文件夹中。 Now, when it goes searching for the particular package my file is located in, it finds the file in its own source tree first. 现在,当搜索我的文件所在的特定程序包时,它将首先在其自己的源树中找到该文件。 Hooray! 万岁!

Why does this work? 为什么这样做? I haven't a clue, perhaps someone could enlighten us to that fact. 我不知道,也许有人可以启发我们了解这一事实。
Does it work? 它行得通吗? For now... 目前...

There is how I fix the problem: 有解决方法:

  • Remove OrmLite from Build Path of the test project. 从测试项目的“构建路径”中删除OrmLite。
  • Export them from the main project. 从主项目中导出它们。

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

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