【发布时间】:2012-01-04 02:06:49
【问题描述】:
我正在尝试创建一个简单的测试应用程序,它通过从外部 JAR 调用一些简单的功能来扩展 Android Hello World 教程应用程序。但是,当我运行该应用程序时,它无法从 JAR 中找到该类。我做错了什么?
这是 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 ++”源代码:
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 中得到这个:
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
然后
11-22 12:24:52.713 2963 2963 E AndroidRuntime: java.lang.NoClassDefFoundError: com.mytests.pow.power2
我做错了什么?谢谢!
顺便说一句,我的实际目标是在 Android 应用中使用真正的 JAR(而不是这个玩具)。我可能可以访问该 JAR 的代码并且可能能够重新构建它,但它是一大段 Java 代码,在重新构建它时我可能会遇到问题,因此我尝试使用预构建的 JAR。
【问题讨论】:
-
您是否将 Jar 添加到项目的构建路径中?
-
project->properties->java build path->libraries tab->Add External JARs。这是您指的,还是我必须采取的其他步骤?