before use Async Tasks my code is work. So i have done some changes in my code and now progress bar is showing up but getting the below errors.
Log cat:
08-07 06:43:15.875: E/AndroidRuntime(1734): FATAL EXCEPTION: AsyncTask #1
08-07 06:43:15.875: E/AndroidRuntime(1734): java.lang.RuntimeException: An error occured while executing doInBackground()
08-07 06:43:15.875: E/AndroidRuntime(1734): at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-07 06:43:15.875: E/AndroidRuntime(1734): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-07 06:43:15.875: E/AndroidRuntime(1734): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-07 06:43:15.875: E/AndroidRuntime(1734): ... 18 more
mycode:
protected String doInBackground(String... args) {
final EditText eKey = (EditText) findViewById(R.id.edtxt_key);
inputs = eKey.getText().toString();
if (inputs.matches("")) {
} else {
keys = url + inputs;
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(keys);
try {
satu = json.getJSONObject(TAG_1);
String two = satu.getString(TAG_2);
String three = satu.getString(TAG_3);
if (two.matches("") | three.matches("")) {
AlertDialog.Builder builder = new AertDialog.Builder(MainActivity.this);
builder.setMessage("not found!").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
eKey.setText("");
status.setText("Key not found!");
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Intent x = new Intent(MainActivity.this, result.class);
x.putExtra("bac", two);
x.putExtra("cab", three);
startActivity(x);
eKey.setText("");
keys = "";
inputs = "";
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
What is going wrong? Thanks in advance.
alert.show();
and
eKey.setText("");
cannot be performed in background task. Pass a return value from
doInBackground()
to
onPostExecute()
method and perform UI tasks there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With