AsyncTask 不执行并且 return java.lang.VerifyError
AsyncTask doesn't execute and return java.lang.VerifyError
我有一个AsyncTask
,代码如下
private void getJSON(final String urlWebService) {
class GetJSON extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExcute();
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json);
}
return sb.toString().trim();
} catch (Exception e) {
Log.i("BG Exception", e.getMessage());
return "";
}
}
}
new GetJSON().execute();
但是,不幸的是它 returns error
如下所示
java.lang.VerifyError: Verifier rejected class net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON due to bad method void net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON.<init>(net.simplifiedlearning.androidjsonparsing.MainActivity, java.lang.String) (declaration of 'net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON' appears in /data/app/net.simplifiedlearning.androidjsonparsing-1/base.apk)
05-25 11:04:26.146 29104 29104 E AndroidRuntime at net.simplifiedlearning.androidjsonparsing.MainActivity.getJSON(MainActivity.java:76)
我找到了解决办法。
错误说
Verifier rejected AsyncTask due to bad void
AsyncTask
在 void
方法中。这就是问题所在。虽然,我不知道为什么?
当我移除 AsyncTask
周围的 getJSON()
空隙后,一切都变得正常并且按预期工作。
我有一个AsyncTask
,代码如下
private void getJSON(final String urlWebService) {
class GetJSON extends AsyncTask<Void, Void, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(String s) {
super.onPostExcute();
}
@Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json);
}
return sb.toString().trim();
} catch (Exception e) {
Log.i("BG Exception", e.getMessage());
return "";
}
}
}
new GetJSON().execute();
但是,不幸的是它 returns error
如下所示
java.lang.VerifyError: Verifier rejected class net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON due to bad method void net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON.<init>(net.simplifiedlearning.androidjsonparsing.MainActivity, java.lang.String) (declaration of 'net.simplifiedlearning.androidjsonparsing.MainActivity0000000$GetJSON' appears in /data/app/net.simplifiedlearning.androidjsonparsing-1/base.apk)
05-25 11:04:26.146 29104 29104 E AndroidRuntime at net.simplifiedlearning.androidjsonparsing.MainActivity.getJSON(MainActivity.java:76)
我找到了解决办法。 错误说
Verifier rejected AsyncTask due to bad void
AsyncTask
在 void
方法中。这就是问题所在。虽然,我不知道为什么?
当我移除 AsyncTask
周围的 getJSON()
空隙后,一切都变得正常并且按预期工作。