-1

我想在 android 应用程序中实现 rest webservice 来做到这一点,我从本教程创建类:here

但是当我点击匹配的按钮时出现错误

unfortunetly, android app has stopped

我在 Logcat 中没有任何内容,然后我不知道问题出在哪里

这是事件代码:

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;

我怎样才能做到这一点

4

2 回答 2

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

于 2013-10-03T11:30:52.127 回答
0

这可能是由于很多错误造成的。

您确定它不会因为找不到您的两个 EditText 而崩溃吗?etdit.setText 会导致 NullPointerExceptions。

于 2013-10-03T11:29:20.350 回答