我已经在heroku上部署了一个应用程序,但是使用我的android应用程序获取请求确实有问题。
使用邮递员,一切正常。根据需要仅完成一个请求。 一旦我使用我的Android应用程序,总是会执行两个请求,这是不期望的和不需要的。
Android代码:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, combinedUrl, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("apiOutput");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject singleApiOutput = jsonArray.getJSONObject(i);
// messageOne/Two ist der Key im Json Object (noch)
Integer accessType = singleApiOutput.getInt("accessType");
String messageOne = singleApiOutput.getString("messageOne");
String messageTwo = singleApiOutput.getString("messageTwo");
textToSpeechFromApi = singleApiOutput.getString("textToSpeech");
if (accessType == 1) {
// Wenn mehr als ein JsonObject dann append() statt setText()
textViewTwo.append("Access response: " + messageOne + "\nPrediction: " + messageTwo);
} else {
textViewTwo.append("Access response: " + messageOne);
}
// Make buttonSpeach visible
if (accessType == 1) {
btnSpeach.setVisibility(View.VISIBLE);
imageButton.setVisibility(View.VISIBLE);
textViewThree.setVisibility(View.VISIBLE);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
来自heroku的日志:(忽略单独的日志警告)
2019-06-19T21:05:31.393342+00:00 app[web.1]: [2019-06-19 23:05:31,393]
WARNING in app: Auth Route Start
2019-06-19T21:05:31.393626+00:00 app[web.1]: [2019-06-19 23:05:31,393]
WARNING in app: Access granted
2019-06-19T21:05:31.393828+00:00 app[web.1]: [2019-06-19 23:05:31,393]
WARNING in app: Acc: 6.54 /Gyro: 0.000413 /Magnet: 6.54
2019-06-19T21:05:31.393992+00:00 app[web.1]: [2019-06-19 23:05:31,393]
WARNING in app: timeClass: 4 /ringerMode: 3
2019-06-19T21:05:31.438475+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/base.py:306:
UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version
0.19.2 when using version 0.21.2. This might lead to breaking code or invalid
results. Use at your own risk.
2019-06-19T21:05:31.438479+00:00 app[web.1]: UserWarning)
2019-06-19T21:05:34.108806+00:00 app[web.1]: [2019-06-19 23:05:34,108]
WARNING in app: Auth Route Start
2019-06-19T21:05:34.109249+00:00 app[web.1]: [2019-06-19 23:05:34,109]
WARNING in app: Access granted
2019-06-19T21:05:34.109780+00:00 app[web.1]: [2019-06-19 23:05:34,109]
WARNING in app: Acc: 6.54 /Gyro: 0.000413 /Magnet: 6.54
2019-06-19T21:05:34.109982+00:00 app[web.1]: [2019-06-19 23:05:34,109]
WARNING in app: timeClass: 4 /ringerMode: 3
2019-06-19T21:05:38.415006+00:00 heroku[web.1]: Process running
mem=948M(185.3%)
2019-06-19T21:05:38.415122+00:00 heroku[web.1]: Error R14 (Memory quota
exceeded)
2019-06-19T21:05:38.990216+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/base.py:306:
UserWarning: Trying to unpickle estimator RandomForestClassifier from version
0.19.2 when using version 0.21.2. This might lead to breaking code or invalid
results. Use at your own risk.
2019-06-19T21:05:38.990228+00:00 app[web.1]: UserWarning)
2019-06-19T21:05:39.161668+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/ensemble/base.py:154:
UserWarning: Loky-backed parallel loops cannot be nested below threads,
setting n_jobs=1
2019-06-19T21:05:39.161676+00:00 app[web.1]: n_jobs =
min(effective_n_jobs(n_jobs), n_estimators)
2019-06-19T21:05:39.450996+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/base.py:306:
UserWarning: Trying to unpickle estimator DecisionTreeClassifier from version
0.19.2 when using version 0.21.2. This might lead to breaking code or invalid
results. Use at your own risk.
2019-06-19T21:05:39.451009+00:00 app[web.1]: UserWarning)
2019-06-19T21:05:41.626091+00:00 app[web.1]: [2019-06-19 23:05:41,625]
WARNING in app: ML Output: SITTING or COMPUTER WORK or AT SCHOOL or PHONE ON
TABLE or WITH CO-WORKERS
2019-06-19T21:05:41.626357+00:00 app[web.1]: [2019-06-19 23:05:41,626]
WARNING in app: Duration: 10.233089447021484
2019-06-19T21:05:41.627624+00:00 app[web.1]: 10.14.49.90 - - [19/Jun/2019
23:05:41] "GET /authTest?accessKey=XXX&accValue=6.54&gyroValue=4.129449E-
4&magnetValue=6.54&timeClass=4&ringerMode=3 HTTP/1.1" 200 -
2019-06-19T21:05:41.630905+00:00 heroku[router]: at=info method=GET
path="/authTest?accessKey=XXX&accValue=6.54&gyroValue=4.129449E-
4&magnetValue=6.54&timeClass=4&ringerMode=3"
host=nextleveleistest02.herokuapp.com request_id=65561734-b07b-4815-b9e9-
6800093d6675 fwd="141.70.80.34" dyno=web.1 connect=0ms service=10237ms
status=200 bytes=375 protocol=https
2019-06-19T21:05:45.961051+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/base.py:306:
UserWarning: Trying to unpickle estimator RandomForestClassifier from version
0.19.2 when using version 0.21.2. This might lead to breaking code or invalid
results. Use at your own risk.
2019-06-19T21:05:45.961068+00:00 app[web.1]: UserWarning)
2019-06-19T21:05:45.985955+00:00 app[web.1]:
/app/.heroku/python/lib/python3.6/site-packages/sklearn/ensemble/base.py:154:
UserWarning: Loky-backed parallel loops cannot be nested below threads,
setting n_jobs=1
2019-06-19T21:05:45.985961+00:00 app[web.1]: n_jobs =
min(effective_n_jobs(n_jobs), n_estimators)
2019-06-19T21:05:46.601447+00:00 app[web.1]: [2019-06-19 23:05:46,600]
WARNING in app: ML Output: SITTING or COMPUTER WORK or AT SCHOOL or PHONE ON
TABLE or WITH CO-WORKERS
2019-06-19T21:05:46.601593+00:00 app[web.1]: [2019-06-19 23:05:46,601]
WARNING in app: Duration: 12.492908000946045
2019-06-19T21:05:46.606560+00:00 app[web.1]: 10.38.106.241 - - [19/Jun/2019
23:05:46] "GET /authTest?accessKey=XXX&accValue=6.54&gyroValue=4.129449E-
4&magnetValue=6.54&timeClass=4&ringerMode=3 HTTP/1.1" 200 -
2019-06-19T21:05:46.611652+00:00 heroku[router]: at=info method=GET
path="/authTest?accessKey=XXX&accValue=6.54&gyroValue=4.129449E-
4&magnetValue=6.54&timeClass=4&ringerMode=3"
host=nextleveleistest02.herokuapp.com request_id=37210d28-ba48-4577-b98d-
507a4e8ef117 fwd="141.70.80.34" dyno=web.1 connect=1ms service=12536ms
status=200 bytes=375 protocol=https
问题是机器学习输出未显示在textView中,但生成了输出: 应用中的警告:机器学习输出:坐在或计算机上工作或在学校或电话打开时 桌子或与同事一起
有人可以告诉我我做错了什么吗? 我想提出一个请求,并在我的textview中显示ML输出