好的,我在网站上寻找了一个可能的解决方案,用Android发送一个POST请求,但是我似乎不理解这里使用的截击或启动异步线程来请求的方法。
private RequestQueue signupRequestQ = Volley.newRequestQueue(this);
@Override
public void onClick(View view) {
String postUrl = "https://mypost.url";
signupRequestQ.start();
switch (view.getId()) {
case R.id.signupBtn:
if (((EditText) findViewById(R.id.passwordSignup)).getText().toString().length() < 6) {
Dialog.showInvalidInputFieldsDialog(this,"Password must be longer than 5 characters").show();
} else {
try {
StringRequest strRequest = new StringRequest(Request.Method.POST, postUrl,
response -> {
System.out.println(response);
},
error -> {
System.out.println("What the funk");
}) {
@Override
protected Map<String, String> getParams() {
LinkedHashMap<String, String> postForm = new LinkedHashMap<String, String>();
postForm.put("test", "var");
return postForm;
}
};
signupRequestQ.add(strRequest);
} catch (ParseException e) {
System.out.println("Something went wrong");
}
}
}
由于某些原因,此代码导致我的应用程序崩溃
java.lang.RuntimeException
和
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getCacheDir()' on a null object reference
是的。
但是,我不应该遇到Null PoExtExchange,因为Volley RequestQueue javadoc清楚地指出,我只需要为我所做的NeWReestStError方法提供上下文。
有谁能帮我解决这个问题吗?谢谢您!