Answer the question
In order to leave comments, you need to log in
Why does android application crash when calling okhttp?
Here is a log:
D/CONNECT:: START
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.run18.flirtodrom, PID: 5385
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.d(Log.java:143)
at com.example.run18.flirtodrom.PlaceItem$GetProductDetails$1.run(PlaceItem.java:107)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
class GetProductDetails extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(PlaceItem.this);
pDialog.setMessage("Loading product details. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String[] params) {
runOnUiThread(new Runnable() {
public void run() {
Log.d("CONNECT: ", "START");
try {
//GET
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url_db + "?action=get_place_by_id&id=" + pid).build();
Response response = client.newCall(request).execute();
String result = response.body().string();
Log.d("CONNECT: ", "OK");
/*JSONArray productObj = new JSONArray(result);
try {
if (1 == 1) {
JSONObject product = productObj.getJSONObject(0);
txtName = (EditText) findViewById(R.id.inputName);
txtPrice = (EditText) findViewById(R.id.inputPrice);
txtDesc = (EditText) findViewById(R.id.inputDesc);
txtName.setText(product.getString(TAG_NAME));
txtPrice.setText(product.getString(TAG_PRICE));
txtDesc.setText(product.getString(TAG_DESCRIPTION));
} else {
// продукт с pid не найден
}
} catch (JSONException e) {
e.printStackTrace();
}*/
} catch (Exception e) {
Log.d("CONNECT: ", e.getMessage());
}
}
});
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
Answer the question
In order to leave comments, you need to log in
You can tell by the line number where it breaks: PlaceItem.java:107 .
Most likely inside catch when executing Log.d("CONNECT: ", e.getMessage()); due to null e.getMessage().
Leave only e there, and then you will see what kind of exception occurs when executing () .
} catch (Exception e) {
Log.d("CONNECT: ", e.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question