Alright, I've looked all over the website for a possible solution to send a POST request using android but I don't seem to understand the usage of Volley here or the method which was starting an async thread to make the request.
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");
}
}
}
For some reason, this code causes my app to crash with a java.lang.RuntimeException
and java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getCacheDir()' on a null object reference
.
However, I should not be encountering the NullPointerException as the Volley RequestQueue javadoc clearly stated that I only had to provide a context for the newRequestQueue method which I did.
Could anyone please help with my issue? Thank you!