可能重复:
Android 运行时验证错误
我正在尝试让一个应用程序显示来自 YouTube 上一个名为 illbehonest 的频道的可用视频列表。我究竟做错了什么?我正在使用 Java-JSON 库来做到这一点。每次我尝试进入 VideoPlay 活动时,应用程序都会关闭(顺便说一下,它的名称与其功能无关)。这是代码:
package com.aer.illbehonest;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.commons.io.IOUtils;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class VideoPlay extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_play);
new ShowTitlesTask().execute("");
}
class ShowTitlesTask extends AsyncTask<String, Void, ArrayList<String>> {
ArrayList<String> titlesList;
@Override
protected ArrayList<String> doInBackground(String... args) {
URL jsonURL = null;
try {
jsonURL = new URL("http://gdata.youtube.com/feeds/api/users/illbehonest/uploads?v=2&alt=jsonc");
} catch (MalformedURLException e3) {
e3.printStackTrace();
}
URLConnection jc = null;
try {
jc = jsonURL.openConnection();
} catch (IOException e2) {
e2.printStackTrace();
}
InputStream is = null;
try {
is = jc.getInputStream();
} catch (IOException e1) {
e1.printStackTrace();
}
String jsonTxt = null;
try {
jsonTxt = IOUtils.toString(is);
} catch (IOException e) {
e.printStackTrace();
}
JSONObject json = (JSONObject) JSONSerializer.toJSON(jsonTxt);
JSONObject jdata = json.getJSONObject("data");
JSONArray jentry = jdata.getJSONArray("items");
for (int entryNumber = 0; entryNumber<=25; entryNumber++){
JSONObject entry = jentry.getJSONObject(entryNumber);
titlesList.add(entry.getString("title"));
}
return titlesList;
}
protected void onPostExecute(ArrayList<String> result) {
ListView listView = (ListView)VideoPlay.this.findViewById(R.id.videolist);
ArrayAdapter<String> adapter = new ArrayAdapter<String> (VideoPlay.this,
android.R.layout.simple_list_item_1, android.R.id.text1, titlesList);
(listView).setAdapter(adapter);
}
}
}
这是 LogCat 输出:
01-14 16:58:36.699: W/dalvikvm(11938): Unable to resolve superclass of Lnet/sf/json/JSONException; (1034)
01-14 16:58:36.707: W/dalvikvm(11938): Link of class 'Lnet/sf/json/JSONException;' failed
01-14 16:58:36.707: W/dalvikvm(11938): VFY: unable to resolve exception class 813 (Lnet/sf/json/JSONException;)
01-14 16:58:36.707: W/dalvikvm(11938): VFY: unable to find exception handler at addr 0x2e
01-14 16:58:36.707: W/dalvikvm(11938): VFY: rejected Lnet/sf/json/JSONSerializer;.toJSON (Ljava/lang/Object;Lnet/sf/json/JsonConfig;)Lnet/sf/json/JSON;
01-14 16:58:36.707: W/dalvikvm(11938): VFY: rejecting opcode 0x0d at 0x002e
01-14 16:58:36.707: W/dalvikvm(11938): VFY: rejected Lnet/sf/json/JSONSerializer;.toJSON (Ljava/lang/Object;Lnet/sf/json/JsonConfig;)Lnet/sf/json/JSON;
01-14 16:58:36.707: W/dalvikvm(11938): Verifier rejected class Lnet/sf/json/JSONSerializer;
01-14 16:58:36.707: W/dalvikvm(11938): threadid=11: thread exiting with uncaught exception (group=0x41b28930)
01-14 16:58:36.707: E/AndroidRuntime(11938): FATAL EXCEPTION: AsyncTask #1
01-14 16:58:36.707: E/AndroidRuntime(11938): java.lang.RuntimeException: An error occured while executing doInBackground()
01-14 16:58:36.707: E/AndroidRuntime(11938): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-14 16:58:36.707: E/AndroidRuntime(11938): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.lang.Thread.run(Thread.java:856)
01-14 16:58:36.707: E/AndroidRuntime(11938): Caused by: java.lang.VerifyError: net/sf/json/JSONSerializer
01-14 16:58:36.707: E/AndroidRuntime(11938): at com.aer.illbehonest.VideoPlay$ShowTitlesTask.doInBackground(VideoPlay.java:63)
01-14 16:58:36.707: E/AndroidRuntime(11938): at com.aer.illbehonest.VideoPlay$ShowTitlesTask.doInBackground(VideoPlay.java:1)
01-14 16:58:36.707: E/AndroidRuntime(11938): at android.os.AsyncTask$2.call(AsyncTask.java:287)
01-14 16:58:36.707: E/AndroidRuntime(11938): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
01-14 16:58:36.707: E/AndroidRuntime(11938): ... 4 more