-1

I want to implement rest webservice in android application to do that I create the class from this tutorial: here

but when I clcok on the matched button I have the error

unfortunetly, android app has stopped

I don't have anything in the Logcat then I canno't know from which is the problem

here is the event code:

case R.id.btn_rest_test :
        Log.d("method event get", "execite :)");
        Rest r = new Rest();
        r.get("http://www.cheesejedi.com/rest_services/get_big_cheese.php?puzzle=1");
        r.getResponseString();
        EditText etdit = (EditText) findViewById(R.id.rest_text);
        EditText etdit2 = (EditText) findViewById(R.id.rest_error_text);
        etdit.setText(r.getResponseText());
        etdit2.setText(r.getError());
        break;

how can I achieve that

Cœur
  • 37,241
  • 25
  • 195
  • 267
begiPass
  • 2,124
  • 6
  • 36
  • 57
  • 2
    Likely http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception – laalto Oct 03 '13 at 11:30
  • It looks like you are executing this Request on the Main thread. This may work on pre-Honeycoumb but on the later android OS will throw a NetworkOnMainThreadException as @laalto is referring to. – hylander0 Oct 03 '13 at 15:57

2 Answers2

0

This could be due to a lot of errors.

Are you sure it does not crash because of your two EditTexts not being found? etdit.setText would cause NullPointerExceptions.

Thomly
  • 200
  • 1
  • 9
0

Did u try to check the response Its something like this:

[{"id":"755","level":"1","time_in_secs":"3","par":"0","initials":"KiB","quote":"Got'cha!","time_stamp":"2012-04-09 22:50:52"},{"id":"977","level":"1","time_in_secs":"3","par":"0","initials":"WJF","quote":"dats right numero uno","time_stamp":"2013-03-11 02:29:36"},{"id":"874","level":"1","time_in_secs":"3","par":"0","initials":"WJF","quote":"Look, Ma. No hands!","time_stamp":"2012-05-25 15:44:10"},{"id":"59","level":"1","time_in_secs":"4","par":"0","initials":"TMF","quote":"Hey hey ole ' hickery","time_stamp":"2012-03-03 04:36:15"},{"id":"61","level":"1","time_in_secs":"4","par":"0","initials":"WJF","quote":"I'm on a boat!","time_stamp":"2012-03-03 04:38:54"}]

As you can see its not ResponseString its a ResponseArray. Modify it accordingly.

Also check whether it type is POST or GET

Terril Thomas
  • 1,486
  • 13
  • 32