red*_*red 8 java android jsoup
我使用eclipse版本:Indigo Service Release 2 Build id:20120216-1857.Android版本是2.2.我创建了一个应用来测试连接并解析一个这样的网站:
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) {
}
}
}
Run Code Online (Sandbox Code Playgroud)
清单文件:
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>
Run Code Online (Sandbox Code Playgroud)
我将库jsoup-1.6.1.jar添加到JAVA Buildpath,但我成了运行时错误:E/AndroidRuntime(736):java.lang.NoClassDefFoundError:org.jsoup.Jsoup
我该如何解决这个错误?
Joh*_*nor 19
最近更新了Android的ADT组件后,我遇到了这个确切的问题.看起来Android忽略了构建路径,而是使用ANT默认值.
我通过从构建路径中删除我的jar文件解决了这个问题,在应用程序heirarchy(与src,gen等一起)的"root"中创建了一个名为"libs"的文件夹,并将我的.jar放在那里.当您清理/构建并重新启动应用程序时,错误应该消失.
仅供参考 - 出现这种情况是因为JAR文件未打包到.apk文件中 - 这就是它正确构建的原因,但在Android设备的运行时无法使用.
请参阅NoClassDefFoundError - Eclipse和Android
| 归档时间: |
|
| 查看次数: |
14291 次 |
| 最近记录: |