私はandroid / javaが初めてですが、c#と.Netの高度な知識があります。
AsyncTaskに問題があります。
私のコード:
import android.os.AsyncTask;
public class testtask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
String response = ""; // BREAKPOINT HERE
return "";
}
@Override
protected void onPostExecute(String result) {
}
}
そして呼び出し:
public void RequestDepartments(View view) {
BamakiWebService service = new BamakiWebService();
RequestType request = new RequestType();
request.Uri = "departments/all";
try {
testtask task = new testtask();
task.execute("wfwef");
}
catch (Exception ex) {
Log.e("Main", ex.getMessage());
}
}
URLにアクセスできないため、コードが失敗します!? doInBackgroundをデバッグし、監視するURLを追加すると、「ローカル変数「urls」が見つかりません」と表示されます。 (BreakPoint-> //ここでBREAKPOINTで)
私が間違っているのは何ですか?!
EDIT
実行の変更
testtask task = new testtask();
String[] params = new String[] {"wfwef"};
task.execute(params);
問題を解決しなかった...
回答:
回答№1は0文字列配列を渡す必要はありません!文字列を1つだけ渡す場合は、その文字列にアクセスできます doInBackground
urls [0]で!それが役に立てば幸い
yourAsyncTask.execute(Your URL String);
そして doInBackground
配列で行うのと同じようにURLにアクセスします。 urls [0]
回答№2の場合は-1
execute()に文字列ではなく、パラメータとして文字列配列を指定します。 doInBackground(String ... urls) urls [0]、urls [1]などで取得できます。