【发布时间】:2020-04-06 09:09:41
【问题描述】:
我有一个简单的数据库/服务器设置,到目前为止工作正常。我有一个应用程序,我正在测试 Volley 的工作原理。
基本上,我有一个“用户”数据库,其中每个 JSON 对象都有一个唯一的 ID、用户名、电子邮件和密码。
我有一个名为 updateUser upUser 的 Volley 函数,它获取那个人的 ID 号以及一个新的用户名。此函数只是更改该用户的用户名。因此,如果我有ID: 5, User: test,并且我在地址栏中输入:"stringServerURL:8080/upUser/5/newTEST",它会将 ID#5 的用户名从test 更改为newTEST。到目前为止按预期工作。
从android端,我有一个方法
public void updateRecords(volleyHttpRequest r, String info, int id){
final volleyHttpRequest req = r;
final String str = info;
final int num = id;
new Thread(new Runnable() {
@Override
public void run() {
req.makearequest("http://some-server-address:8080/upUser/" + num + "/" + str);
}
});
// Toast.makeText(getApplicationContext(), "Username updated.", Toast.LENGTH_SHORT).show();
}
volleyHttpRequest r 参数为:
pDialog = new ProgressDialog(this.getApplicationContext());
final volleyHttpRequest request = new volleyHttpRequest(pDialog,0);
makearequest() 方法是:
public void makearequest(String url) {
StringRequest strReq = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
hideProgressDialog();
}
});
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
所以它不会崩溃或任何东西,而且它似乎可以工作,但是当我为num 传递 5 和为str 传递“newTEST”时,没有任何更新。我尝试尽可能地遵循在线教程,但它只有在我直接从地址栏更新时才有效。
我确实在“日志”中找到了这个:
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
D/OpenGLRenderer: endAllActiveAnimators on 0xd602b680 (RippleDrawable) with handle 0xd69882a0
W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection
W/IInputConnectionWrapper: getSelectedText on inactive InputConnection
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
D/EGL_emulation: eglMakeCurrent: 0xea072a00: ver 3 0 (tinfo 0xd690b5e0)
我认为这与非活动输入连接有关,但服务器正在运行,我不知道在哪里查看。
任何帮助将不胜感激。
【问题讨论】:
标签: java android android-studio server android-volley