Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Async task Run time Exception Error.
    primarykey
    data
    text
    <p>I am doing a decryption task in android platform. At first, I create a method called RunDecrypt. It's work fine when I press the button in my UI. The method shown below:</p> <pre><code>public void runDecrypt() throws IOException{ EditText editText = (EditText) findViewById(R.id.fileName); EditText editText2 = (EditText) findViewById(R.id.keyName); String fileName = editText.getText().toString(); String keyName = editText2.getText().toString(); File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard , fileName); File key = new File(sdcard, keyName); BufferedReader brFile; String Cipher = null; try{ //Read file line by line and concat each line of string in file with space character. FileInputStream fstream = new FileInputStream(file); brFile = new BufferedReader(new InputStreamReader(fstream)); String tempString; while((tempString = brFile.readLine()) != null){ if(Cipher == null){ Cipher = tempString; }else{ Cipher = Cipher.concat(" "); Cipher = Cipher.concat(tempString); } } }catch(Exception e){ //messageBox("Decrypt", e.getMessage()); } BufferedReader brKey; String DecKey = null; try{ FileInputStream fstream = new FileInputStream(key); brKey = new BufferedReader(new InputStreamReader(fstream)); DecKey = brKey.readLine(); }catch(Exception e){ //messageBox("Decrypt", e.getMessage()); } try{ byte[] cipherByte = DES.parseBytes(Cipher); String decKey = DES.convertStringToHex(DecKey); byte[] keyByte = DES.parseBytes(decKey); String decryptResult = DES.hex(DES.decryptCBC(cipherByte, keyByte)); String temp = decryptResult.replace(" ", ""); String finalDecrypt = temp.substring(0, (temp.length() - DES.getConcatCount())); String finResult = DES.convertHexToString(finalDecrypt); TextView FinalResult = (TextView)findViewById(R.id.decryptText); FinalResult.setText(finResult); }catch(Exception e){ messageBox("Decrypt", "Please Upload File Properly"); } } </code></pre> <p>Since it's work fine, I try to implement this method with Async Task for running my work in background. The class that implemented shown below:</p> <pre><code>private class runDecrypt extends AsyncTask &lt;URL , Integer, Long&gt; { private final ProgressDialog dialog = new ProgressDialog(Homepage.this); AlertDialog.Builder builder = new AlertDialog.Builder(Homepage.this); @SuppressWarnings("resource") @Override protected Long doInBackground(URL... params) { EditText editText = (EditText) findViewById(R.id.fileName); EditText editText2 = (EditText) findViewById(R.id.keyName); String fileName = editText.getText().toString(); String keyName = editText2.getText().toString(); File sdcard = Environment.getExternalStorageDirectory(); File file = new File(sdcard , fileName); File key = new File(sdcard, keyName); BufferedReader brFile; String Cipher = null; try{ //Read file line by line and concat each line of string in file with space character. FileInputStream fstream = new FileInputStream(file); brFile = new BufferedReader(new InputStreamReader(fstream)); String tempString; try { while((tempString = brFile.readLine()) != null){ if(Cipher == null){ Cipher = tempString; }else{ Cipher = Cipher.concat(" "); Cipher = Cipher.concat(tempString); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }catch(java.io.FileNotFoundException e){ System.out.println("File could not be found."); } BufferedReader brKey; String DecKey = null; try{ FileInputStream fstream = new FileInputStream(key); brKey = new BufferedReader(new InputStreamReader(fstream)); try { DecKey = brKey.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }catch(java.io.FileNotFoundException e){ System.out.println("Key file could not be found."); } String decKey = DES.convertStringToHex(DecKey); byte[] cipherByte = DES.parseBytes(Cipher); byte[] keyByte = DES.parseBytes(decKey); String decryptResult = DES.hex(DES.decryptCBC(cipherByte, keyByte)); String temp = decryptResult.replace(" ", ""); String finalDecrypt = temp.substring(0, (temp.length() - DES.getConcatCount())); String finResult = DES.convertHexToString(finalDecrypt); TextView FinalResult = (TextView)findViewById(R.id.decryptText); FinalResult.setText(finResult); return null; } protected void onPreExecute() { this.dialog.setMessage("Decrypting..."); this.dialog.show(); } protected void onPostExecute(Long result) { if (this.dialog.isShowing()) { this.dialog.dismiss(); } builder.setMessage("Decryption Completed"); builder.show(); } protected void onProgressUpdate(int progress) { setProgress(progress * 100); } } </code></pre> <p>My onClick method:</p> <pre><code>public void onClick (View v){ Intent browse = new Intent(this, Browse.class); switch (v.getId()){ case R.id.browseFile: browse.putExtra("browse","file"); startActivityForResult(browse, 1); break; case R.id.browseKey: browse.putExtra("browse", "key"); startActivityForResult(browse, 1); break; case R.id.decrypt: new runDecrypt().execute(); break; default: break; } } </code></pre> <p>My logcat shown below: <img src="https://i.stack.imgur.com/RG8F2.png" alt="logcat"></p> <p>Can Anyone please help? Thank you and appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload