Hi android enthusiast
I am trying to build a login/registration app but the below code has been posing a challenge which is the async task,
whenever i test it on my device pressing the register button it always crash and shows the below error in the logcat
Logcat error below
780 7570-7676/com.myfonetv.a3wc.myfonetv D/libc-netbsd: getaddrinfo: staging.streamhash.info NO result from proxy
08-17 16:20:54.784 7570-7676/com.myfonetv.a3wc.myfonetv I/System.out: [CDS][DNS]Unable to resolve host "staging.streamhash.info": No address associated with hostname
08-17 16:20:54.784 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: java.net.UnknownHostException: Unable to resolve host "staging.streamhash.info": No address associated with hostname
08-17 16:20:54.787 7570-7729/com.myfonetv.a3wc.myfonetv D/Surface: Surface::setBuffersDimensions(this=0x7f8060c600,w=480,h=800)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:479)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.net.InetAddress.getAllByNameImpl(InetAddress.java:259)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.net.InetAddress.getAllByName(InetAddress.java:221)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:147)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:169)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:124)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:365)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:602)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:522)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:500)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at com.myfonetv.a3wc.myfonetv.activities.Register$6.doInBackground(Register.java:555)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at com.myfonetv.a3wc.myfonetv.activities.Register$6.doInBackground(Register.java:516)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:292)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.lang.Thread.run(Thread.java:818)
08-17 16:20:54.793 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
08-17 16:20:54.794 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at libcore.io.Posix.android_getaddrinfo(Native Method)
08-17 16:20:54.794 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55)
08-17 16:20:54.794 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: at java.net.InetAddress.lookupHostByName(InetAddress.java:445)
08-17 16:20:54.794 7570-7676/com.myfonetv.a3wc.myfonetv W/System.err: ... 17 more
08-17 16:20:54.801 7570-7729/com.myfonetv.a3wc.myfonetv D/Surface: Surface::setBuffersDimensions(this=0x7f8060c600,w=480,h=800)
08-17 16:20:54.804 7570-7570/com.myfonetv.a3wc.myfonetv D/AndroidRuntime: Shutting down VM
08-17 16:20:54.812 7570-7570/com.myfonetv.a3wc.myfonetv E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myfonetv.a3wc.myfonetv, PID: 7570
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
at org.json.JSONTokener.nextValue(JSONTokener.java:94)
at org.json.JSONObject.<init>(JSONObject.java:156)
at org.json.JSONObject.<init>(JSONObject.java:173)
at com.myfonetv.a3wc.myfonetv.activities.Register$6.onPostExecute(Register.java:582)
at com.myfonetv.a3wc.myfonetv.activities.Register$6.onPostExecute(Register.java:516)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5643)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
See my code below
case R.id.register:
if (ConnectionHelper.isConnectingToInternet(Register.this)) {
Boolean flag = false;
final String str_email, str_pass, str_fName, str_phone;
str_email = edt_email.getText().toString();
str_pass = edt_password.getText().toString();
str_fName = edt_f_name.getText().toString();
str_phone = edt_phone.getText().toString();
if ((!isValidEmail(str_email))) {
assert lay_email != null;
lay_email.setError("Required Field");
flag = true;
}
if (str_pass.length() <= 0) {
lay_password.setError("Required Field");
flag = true;
}
if (str_fName.length() <= 0) {
lay_f_name.setError("Required Field");
flag = true;
}
if (str_phone.length() <= 0) {
lay_phone.setError("Required Field");
flag = true;
}
if (!flag) {
new AsyncTask<String, Void, String>() {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressBar.setVisibility(View.VISIBLE);
}
@SuppressWarnings("deprecation")
@Override
protected String doInBackground(String... params) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URLUtils.register);
entityBuilder = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
if (path.isEmpty()) {
Log.e("doInBack_file", ": is empty");
} else {
File file = new File(path);
Log.e("doInBack_file", "" + file);
entityBuilder.addPart("picture", new FileBody(file, "application/octet"));
Log.d("EDIT USER PROFILE", "UPLOAD: file length = " + file.length());
Log.d("EDIT USER PROFILE", "UPLOAD: file exist = " + file.exists());
}
entityBuilder.addPart("device_token", new StringBody(SingleTon.getInstance().GCMKey));
entityBuilder.addPart("device_type", new StringBody("android"));
entityBuilder.addPart("login_by", new StringBody("manual"));
entityBuilder.addPart("name", new StringBody(str_fName));
entityBuilder.addPart("email", new StringBody(str_email));
entityBuilder.addPart("mobile", new StringBody(str_phone));
entityBuilder.addPart("password", new StringBody(str_pass));
entityBuilder.addPart("social_unique_id", new StringBody(""));
httpPost.setEntity(entityBuilder);
HttpResponse response = client.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
if (response.getStatusLine().getStatusCode() == 200) {
String res = EntityUtils.toString(httpEntity);
Log.e("res", "" + res);
return res;
} else {
return "Error";
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
progressBar.setVisibility(View.GONE);
if (s != null && s.equalsIgnoreCase("Error")) {
UIUtils.showToast(Register.this, R.string.con_timeout);
} else {
try {
JSONObject object = new JSONObject(s);
Log.i("object", "" + object);
String result = object.optString("success");
if (result.equalsIgnoreCase("true")) {
Intent mainIntent = new Intent(Register.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
SharedPref.putKey(Register.this, "login_type", "Logged");
SharedPref.putKey(Register.this, "ID", object.optString("id"));
SharedPref.putKey(Register.this, "PROFILE_IMAGE", object.optString("picture"));
SharedPref.putKey(Register.this, "NAME", object.optString("name"));
SharedPref.putKey(Register.this, "TOKEN", object.optString("token"));
SharedPref.putKey(Register.this, "SUB_PROFILE", object.optString("sub_profile_id"));
SharedPref.putKey(Register.this, "user_type", object.optString("user_type"));
SharedPref.putKey(Register.this, "push_status", object.optString("push_status"));
SharedPref.putKey(Register.this, "CHANGE_PASS", "");
startActivity(mainIntent);
Register.this.finish();
} else {
UIUtils.showToastMsg(Register.this, object.optString("error_messages"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}.execute();
}
} else {
UIUtils.showNetworkAlert(Register.this, R.string.check_network);
}
break;
}
Kindly help
What I have tried:
I have google stackoverflow for solution but to no avail