AsyncTask不执行并返回java.lang.VerifyError

时间:2018-05-25 05:48:17

标签: java android 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();

但不幸的是,它会返回error,如下所示

java.lang.VerifyError: Verifier rejected class net.simplifiedlearning.androidjsonparsing.MainActivity$100000000$GetJSON due to bad method void net.simplifiedlearning.androidjsonparsing.MainActivity$100000000$GetJSON.<init>(net.simplifiedlearning.androidjsonparsing.MainActivity, java.lang.String) (declaration of 'net.simplifiedlearning.androidjsonparsing.MainActivity$100000000$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)

1 个答案:

答案 0 :(得分:0)

我找到了它的解决方案。 错误说

Verifier rejected AsyncTask due to bad void

AsyncTask采用void方法。这就是问题所在。虽然,我不知道为什么?

当我删除围绕getJSON()的{​​{1}}空洞时,一切都变得很好并且预期会有效。