Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

ariel kotch
55 PointsI am trying to do a JSON POST Request in android studio and my app keeps crashing and wont go through....Whats wroung?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
searchActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mEditText = (EditText) findViewById(R.id.Edit_Text);
mButton = (Button) findViewById(R.id.Postbutton);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println(mButton);
String readText = mEditText.getText() + " ";
System.out.print(readText.length());
if (readText.length() == 1) {
Toast toast = Toast.makeText(getApplicationContext(),
"Please Enter a Question", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
return;
}
mVolleySingleton = VolleySingleton.getInstance();
mRequestQueue = mVolleySingleton.getRequestQueue();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, insertUrl,new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println(response+"reponse");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println(error+"error");
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String>parameters=new HashMap<String, String>();
parameters.put("text", mEditText.getText().toString());
parameters.put("id", "0");
parameters.put("studentId", "1");
System.out.println(parameters+"parameters");
return parameters;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("content-type", "application/json; charset=utf-8");
System.out.println(params);
return params;
}
};
System.out.println(request+"request");
mrequestQueue.add(request);
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id=item.getItemId();
if(id==R.id.action_settings){
return true;
}
if(id==android.R.id.home){
NavUtils.navigateUpFromSameTask(this);
}
return super.onOptionsItemSelected(item);
}
}