Yogesh Kadam Yogesh Kadam - 2 months ago 28
Android Question

Why i get this Error "An error occured while executing doInBackground()" .where i am wrong?

Why am I getting this Error


An error occured while executing doInBackground()


Where am I wrong? LogCat is shown below

Here's my LoginActivity.java

public class LoginActivity extends AppCompatActivity {
private static EditText username_edit_text;
private static Button login_button;
private static RadioGroup lang_group;
RadioButton mar_radio_button;
RadioButton eng_radio_button;
TextView tv;
String lang = "en";
private Locale myLocale;
Resources res;
private final String NAMESPACE = "http://tempuri.org/";
private final String URL = "http://My_server_ip/MobileLDAP/Service.asmx";
private final String SOAP_ACTION = "http://tempuri.org/OMS_Authenticate_Crew";
private final String METHOD_NAME = "OMS_Authenticate_Crew";
private static String username;
private static String resultm;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final ConnectionDetector cd = new ConnectionDetector();
username_edit_text = (EditText) findViewById(R.id.ET_UserName);
login_button = (Button) findViewById(R.id.Button_login);
lang_group = (RadioGroup) findViewById(R.id.radioType);
mar_radio_button = (RadioButton) findViewById(R.id.radioMar);
eng_radio_button = (RadioButton) findViewById(R.id.radioEng);
tv = (TextView) findViewById(R.id.tv);
setTitle(getResources().getString(R.string.app_name));
res = getResources();
final Locale locale = res.getConfiguration().locale;
lang_group.setOnCheckedChangeListener(
new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (locale.getLanguage().equals("mr")) {
mar_radio_button.setEnabled(false);
if (eng_radio_button.isChecked()) {
lang = "en";
setLocale(lang);
}
} else {
eng_radio_button.setEnabled(false);
if (mar_radio_button.isChecked()) {
lang = "mr";
setLocale(lang);
}
}
}
});

login_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
username = username_edit_text.getText().toString();
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
});
}

protected void isAuthenticate(String Payroll_no) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo Payroll_info = new PropertyInfo();
Payroll_info.setName("Payroll_no");
Payroll_info.setValue(Payroll_no);
Payroll_info.setType(double.class);
request.addProperty(Payroll_info);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resultm = response.toString();
} catch (Exception e) {
resultm = e.toString();
}
}

private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
isAuthenticate(username);
return null;
}

@Override
protected void onPostExecute(Void result) {
tv.setText(resultm);
}

@Override
protected void onPreExecute() {
}

@Override
protected void onProgressUpdate(Void... values) {
}
}

public void setLocale(String lang) {
myLocale = new Locale(lang);
res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
sharedPreferences = getSharedPreferences("CommonPref", Activity.MODE_PRIVATE);
Intent refresh = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(refresh);
finish();
}
}


I'm not doing any UI work in doInBackGround function but I still get this error.

LogCat:

09-26 02:20:32.209 27677-27897/com.gis.reliance.customercomplaintreports E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.gis.reliance.customercomplaintreports, PID: 27677
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.VerifyError: org/ksoap2/SoapEnvelope
at com.gis.reliance.customercomplaintreports.activity.LoginActivity.isAuthenticate(LoginActivity.java:141)
at com.gis.reliance.customercomplaintreports.activity.LoginActivity$AsyncCallWS.doInBackground(LoginActivity.java:160)
at com.gis.reliance.customercomplaintreports.activity.LoginActivity$AsyncCallWS.doInBackground(LoginActivity.java:157)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
at java.lang.Thread.run(Thread.java:841) 

Answer

Your error is in authentication. Check the value of username you are passing in this method and see if it is legal and valid.

 protected Void doInBackground(String... params) {
      isAuthenticate(username);
    return null;

I don't see where you are setting your username variable it seems null.

EDIT: Also make sure that your application run-time JVM and dependent lib JVM versions don't differ.