android无法从外部jar中找到类 [英] android can't find class from external jar

查看:43
本文介绍了android无法从外部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

我做错了什么?谢谢!

顺便说一下,我的实际目标是在 Android 应用中使用真正的 JAR(而不是这个玩具).我可能有权访问该 JAR 的代码并且可能能够重建它,但它是一大段 Java 代码,我在重建它时可能会遇到问题,因此我尝试使用预先构建的 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.

推荐答案

无需构建外部 jar.尝试从您的构建路径中删除它并按照以下步骤操作:

There's no need to build the external jar. Try removing it from your build path and follow these steps:

  1. 在 Android 项目的根目录中创建一个名为 libs 的文件夹.
  2. 将 jar 添加到该文件夹​​中.
  3. 右键单击该 jar 并单击以添加到构建路径.
  4. 清理您的项目并重试.

这篇关于android无法从外部jar中找到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆