asynctaskでRequestFuture経由でPHPファイルにパラメータを渡そうとしています。私はそれを実行しているクラスは私の主な活動ですが、 問題は、私がasynctaskを実行するときに、 がパラメータを送信していないことです。そして最近、私は 奇妙なエラーを取得してきたが、これは私の主な活動であるリクエストがnullパラメータを送信し続ける
public class MainActivity extends AppCompatActivity {
public TextView textv;
private EditText username;
private EditText password;
public ProgressDialog progressDialog;
public Context c;
public parseActivity a;
private JSONObject params = new JSONObject();
public JSONObject js;
public static String stat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
a = new parseActivity();
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
textv = (TextView) findViewById(R.id.view);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Logging in...");
final Button logb = (Button) findViewById(R.id.login);
logb.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
if(view == logb) {
String user = username.getText().toString();
String pass = password.getText().toString();
try {
params.put("username", user);
params.put("password", pass);
Log.w("tag", "doInBackground: "+params.toString());
} catch (JSONException e) {
e.printStackTrace();
}
textv.setText(params.toString());
c = getApplicationContext();
caller caller = new caller(params,c);
caller.execute();
}
}
});
}
}
あなたは私がここにここに
public class caller extends AsyncTask<Void, Void, JSONObject> {
private parseActivity p = new parseActivity();
private JSONObject params;
private Context c;
private JSONObject js;
public caller(JSONObject param, Context context){
params = param;
c = context;
}
@Override
protected JSONObject doInBackground(Void...param) {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.POST,p.URLS,params ,future,future);
MySingleton.getInstance(c).addToRequestQueue(stringRequest);
try {
js = future.get(10, TimeUnit.SECONDS);
Log.w("tag", "doInBackground: "+js);
return js ;
}catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
e.getCause();
return null;
} catch (TimeoutException e) {
e.printStackTrace();
return null;
}
}
}
されている非同期クラスを実行しています見ることができるようにエラーがない私のPHPコード。
<?php
if(isset($_POST))
{
if(isset($_POST['username']) && isset($_POST['password']))
{
echo json_encode(array("username" => $_POST['username'], "password" => $_POST['password']));
}else{json_encode(array("error" => "nothing set"));}
}else{json_encode(array("error" => "nothing set"));}
?>
、ここでは私が解決策を見つけた幸運なこと
java.util.concurrent.ExecutionException: com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at com.android.volley.toolbox.RequestFuture.doGet(RequestFuture.java:117)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at com.android.volley.toolbox.RequestFuture.get(RequestFuture.java:97)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at com.thetenlaws.password.caller.doInBackground(caller.java:45)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at com.thetenlaws.password.caller.doInBackground(caller.java:26)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:295)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: at java.lang.Thread.run(Thread.java:818)
05-21 16:22:19.378 14198-14453/com.thetenlaws.password W/System.err: Caused by: com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of