2017-11-11 130 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' 
    } 
相關問題