我的工作与Eclipse版本:靛蓝服务版本2版本ID:20120216-1857。 而Android版本IST 2.2。 我做一个应用程序来测试连接和分析一个网站是这样的:
I work with eclipse Version: Indigo Service Release 2 Build id: 20120216-1857. The Android version ist 2.2. I make an app to test a connect and parse a web site like this:
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
Document doc = Jsoup.connect("http://example.com/").get();
Elements divs = doc.select("div#test");
for (Element div : divs) {
System.out.println(div.text());
}
} catch (Exception e) {
}
}
}
清单文件:
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TestActivity"
android:label="@string/app_name"
android:configChanges="orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<uses-library android :name="org.jsoup.Jsoup" />
</activity>
</application>
我添加库jsoup-1.6.1.jar到JAVA的Buildpath,但我成为了运行时错误: E / AndroidRuntime(736):java.lang.NoClassDefFoundError的:org.jsoup.Jsoup
I add the library jsoup-1.6.1.jar to JAVA Buildpath, but I become the runtime error: E/AndroidRuntime(736): java.lang.NoClassDefFoundError: org.jsoup.Jsoup
我该如何解决这个问题?
How can I resolve this error?
我最近的Android的ADT组件的更新后遇到了这个确切的问题。它看起来像Android正在忽略构建路径,而不是使用ANT默认值。
I encountered this exact problem after a recent update of the ADT component of Android. It looks like Android is ignoring the build path and instead using the ANT defaults.
我解决了这个通过从构建路径中我的jar文件,创建了应用程序层次结构的根的文件夹(SRC旁边,根等)被称为库,并把我的.jar那里。当你清洁/构建并重新启动应用程序,错误应该消失。
I solved this by removing my jar file from the build path, creating a folder in the "root" of the app heirarchy (alongside src, gen, etc) called "libs", and putting my .jar there. When you clean / build and re-launch the app, the error should go away.
仅供参考 - 这是发生因为JAR文件是没有得到打包进.apk文件的文件 - 这就是为什么它建立正确的,但不可用在运行时在Android设备上
FYI - this is occurring because the JAR file is not getting packaged into the .apk files - this is why it builds correctly, but isn't available during run-time on your Android device.
看NoClassDefFoundError - Eclipse和Android的