2017-11-11 133 views
-2

我知道这已被问过几次,但我面临一个问题。 当我将设备连接到系统并运行我的应用程序时,它工作正常。 即使我正在生成一个调试apk并运行应用程序,它工作正常。应用程序在调试模式下工作,但崩溃与发布apk显示java.lang.RuntimeException:Android

然而,在生成签署过的APK的应用程序,我提示以下错误:发布:

FATAL EXCEPTION: AsyncTask #5 
Process: com.xxxx.xxxxx, PID: 8180 
java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:309) 
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) 
at java.util.concurrent.FutureTask.setException(FutureTask.java:223) 
at java.util.concurrent.FutureTask.run(FutureTask.java:242) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
at java.lang.Thread.run(Thread.java:818) 

我无法揣摩出此异常发生,为什么?

请问谁能帮忙?

我已经通过几个环节去为:

我打电话给我的异步任务为,

new BannerAdAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); 

我的异步任务是,

// Checking banner ad and displaying the appropriate banner ad 
class BannerAdAsyncTask extends AsyncTask<String, Boolean, Boolean> { 

    String addUserResponseCode; 
    String responseForAdduserRequest; 
    String msg; 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.os.AsyncTask#onPreExecute() 
    */ 
    @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.os.AsyncTask#doInBackground(Params[]) 
    */ 
    @Override 
    protected Boolean doInBackground(String... params) { 

     try { 

       String fetchBannerURL = context.getString(R.string.site_url) 
         + "fetchbannerad.cfc?method=fetchbannerad"; 

       responseForAdduserRequest = fetchContentFromServer(fetchBannerURL); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     return null; 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.os.AsyncTask#onPostExecute(java.lang.Object) 
    */ 
    @Override 
    protected void onPostExecute(Boolean result) { 
     super.onPostExecute(result); 

     try { 

      if (responseForAdduserRequest != null) { 



      // Parse JSON 

      JSONObject pages = new JSONObject(responseForAdduserRequest); 

      String d = pages.getString("DATA"); 

      JSONArray dd = new JSONArray(d); 

      int len = dd.length(); 

      for (int i = 0; i < dd.length(); i++) { 

       String p = dd.getString(i); 

       JSONArray values = new JSONArray(p); 

       adFileName = values.getString(6); 
       adLinkLocation = values.getString(7); 
      } 


      adBanner.setVisibility(View.VISIBLE); 

      adBanner.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 


        // If the link location contains the companyid field, 
        // fetch the company id and navigate to the app's 
        // companies page with this id 
        if (adLinkLocation.contains("?companyid=")) { 

         int temp = adLinkLocation.indexOf("companyid="); 

         temp = temp + 10; 

         String companyid = adLinkLocation.substring(temp); 

         boolean isNumber = true; 

         try { 

          int id = Integer.parseInt(companyid); 

         } catch (NumberFormatException e) { 
          isNumber = false; 
         } 

         if (isNumber) { 

          Intent intent = new Intent(context, 
            CompanyProfile.class); 
          intent.putExtra("company_id", 
            Integer.parseInt(companyid)); 

          // Get company branches as a cursor 
          final DataAdapter mDbHelper = new DataAdapter(
            context); 
          mDbHelper.createDatabase(); 
          mDbHelper.open(); 

          intent.putExtra("branch_id", primaryBranchID); 
          intent.putExtra("com_name", name); 
          intent.putExtra("com_tradename", tradename); 
          intent.putExtra("com_desc", ""); 
          intent.putExtra("main_branch_id", 
            primaryBranchID); 

          mDbHelper.close(); 

          context.startActivity(intent); 
         } 

        } else { 

         // Otherwise load the link in browser 
         Intent intent = new Intent(
           "android.intent.action.VIEW", Uri 
           .parse(adLinkLocation)); 
         startActivity(intent); 
        } 
       } 
      }); 
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

    } 
} 

这是我从服务器获取内容的方法的代码。我怀疑这个问题在这里得到响应,

private static String fetchContentFromServer(String request) { 

    /* Converting required variables to convert the response */ 
    String line = ""; 
    String responseString = ""; 

    /* Initializing the HTTP client */ 
    HttpClient httpClient = new DefaultHttpClient(); 

    try { 

     /* Read and write connection timeout */ 
     HttpParams httpParameters = new BasicHttpParams(); 

     int timeOutInMillis = 8 * 1000; 
     HttpConnectionParams.setConnectionTimeout(httpParameters, 
       timeOutInMillis); 

     int socketTimeOutinMillis = 8000; 
     HttpConnectionParams.setSoTimeout(httpParameters, 
       socketTimeOutinMillis); 

     /* 
     * Getting the response by giving request and adding it to the 
     * buffer reader to read the content 
     */ 
     HttpResponse httpResponse = httpClient 
       .execute(new HttpGet(request)); 
     InputStream inputStream = httpResponse.getEntity().getContent(); 
     BufferedReader bufferedReader = new BufferedReader(
       new InputStreamReader(inputStream)); 

     /* For all the lines in the response */ 
     while ((line = bufferedReader.readLine()) != null) { 

      /* Appending every line to the result */ 
      responseString += line; 
     } 

     /* Closing the input stream and displaying result in text view */ 
     inputStream.close(); 

    } catch (Exception e) { 

     e.printStackTrace(); 
    } finally { 

     /* Closing the http connection */ 
     httpClient.getConnectionManager().shutdown(); 
    } 

    return responseString; 
} 
+0

发布您的代码,请。 – FarshidABZ

+0

@FarshidABZ请参阅编辑的问题。 – devgeek

+0

@devgeek尝试清理构建项目,然后重新生成已签名的apk。 – Rahulrr2602

回答

2

在我的情况的问题是,我没有在的情况下产生的释放APK而所有的服务器响应被罚款后获得任何类型的服务器响应调试APK。

我加了下面一行在我gradle这个文件,

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
相关问题