Android无法找到外部罐类 [英] android can't find class from external jar
问题描述
我想创建一个简单的测试应用程序,基本上是通过从外部JAR文件调用一些简单的功能,扩展了Android的Hello World教程应用程序。然而,当我运行的应用程序,它找不到从JAR中的类。我究竟做错了什么?
I am trying to create a simple test app that basically extends the Android Hello World tutorial app by invoking some simple functionality from an external JAR. However, when I run the app, it can't find the class from the JAR. What am I doing wrong?
下面是JAR的整个源:
Here's entire source of the JAR:
package com.mytests.pow;
public class power2 {
private double d;
public power2()
{
d = 0.0;
}
public String stp2(double dd)
{
d = dd*dd;
return String.format("%e", d);
}
}
和这里的的Hello World ++来源:
And here's the "Hello World ++" source:
package com.myLuceneTests.namespace;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import com.mytests.pow.*;
public class AndroidSimpleSIH_EclipseActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
power2 pp = new power2();
String iout = pp.stp2(12.0);
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText(iout);
setContentView(tv);
}
}
当我运行应用程序时,我得到这个logcat的:
When I run the app, I get this in logcat:
11-22 12:24:52.697 2963 2963 E dalvikvm: Could not find class 'com.mytests.pow.power2', referenced from method com.myLuceneTests.namespace
.AndroidSimpleSIH_EclipseActivity.onCreate
.AndroidSimpleSIH_EclipseActivity.onCreate
然后
11-22 12:24:52.713 2963 2963 E AndroidRuntime: java.lang.NoClassDefFoundError: com.mytests.pow.power2
我是什么做错了吗?谢谢!
What am I doing wrong? Thanks!
顺便说一句,我的实际目标是用真实的JAR(而不是这个玩具的)在一个Android应用程序。我可能有机会获得code为JAR,可能能够重建它,但它是一个很大的一块的Java code和我有可能重建的时候,所以我想使用的$ P遇到的问题$ P-JAR建
By the way, my actual goal is to use a real JAR (rather than this toy one) in an Android app. I might have access to the code for that JAR and might be able to rebuild it but it's a big piece of Java code and I am likely to encounter problems when rebuilding it so I am trying to use the pre-built JAR.
推荐答案
有没有必要建立外部罐子。尝试从您的构建路径中删除并按照下列步骤操作:
There's no need to build the external jar. Try removing it from your build path and follow these steps:
- 在你的Android项目叫根目录下创建一个文件夹
库
。 - 的jar添加到该文件夹。
- 右键单击该罐,然后单击添加到构建路径。
- 清理项目,然后重试。
- Create a folder in the root of your Android project called
libs
. - Add the jar to that folder.
- Right-click the jar and click to add to build path.
- Clean your project and try it again.
这篇关于Android无法找到外部罐类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!