我想这一定是一个get请求hostname/match?data=“yffyf”
@GET("match")
Call<ResponseBody> add_user(
@Query("data") String data);
但是出现了一个错误
public void sendPost(String gk ) throws IOException {
Call<ResponseBody> call = ApiUtils.getAPIService().add_user(scanResults.getText().toString());
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
String s = response.body().string();
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Toast.makeText(MainActivity.this, t.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
}
ava.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String okhttp3.ResponseBody.string()' on a null object reference
at com.uthoo.www.ocr.MainActivity$3.onResponse(MainActivity.java:95)
at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:70)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6831)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:927)
你能告诉我如何使用post和get来实现这一点吗?谢谢您。。。
暂无答案!
目前还没有任何答案,快来回答吧!