0
可能重複:
Android Runtime Verify Error的AsyncTask的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
有現有的回答你的問題就在這裏http://stackoverflow.com/questions/6280551/android-runtime-verify-error – Bostone
@Bostone我改變了庫,但它仍然強制關閉。我將用新的LogCat輸出更新我的問題。 –
@Bostone實際上,由於JSONSerializer,輸出大致相同,但它不在org.json中......我該怎麼做? –