私のURLに(id、name、family)を得るために3つの編集テキストを使用したいと思います。私はすでにRest Webサービスを作っています。今はAndroidアプリでsocketを使用したいと思います。以下は私のコードがエラーを取得し続けるです。私は何を取りこぼしたか?EditTextを使用してdoInbackGround(AsyncTask)でパラメータを取得するにはどうすればよいですか?
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void ok (View view){
Havij havij = new Havij();
havij.execute();
}
public class Havij extends AsyncTask{
String name="";
@Override
protected Object doInBackground(Object[] objects) {
String str1 = (String) objects[0];
String str2 = (String) objects[1];
String str3 = (String) objects[2];
try {
URL url =new URL("http://192.168.1.100:8083/rest/pm/rp?id=&name=&family="+str1+str2+str3);
URLConnection urlConnection = url.openConnection();
InputStream inputStream = urlConnection.getInputStream();
int ascii = inputStream.read();
String json = "";
while (ascii !=-1){
json += (char) ascii;
ascii = inputStream.read();
}
inputStream.close();
JSONArray jsonArray = (JSONArray) new JSONParser().parse(json);
for (Object o : jsonArray) {
JSONObject jsonObject = (JSONObject) o;
name =name+jsonObject.get("name")+ " ";
}
}
catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
return name;
}
@Override
protected void onPostExecute(Object o) {
EditText editText1 = (EditText) findViewById(R.id.editText1);
EditText editText2 = (EditText) findViewById(R.id.editText2);
EditText editText3 = (EditText) findViewById(R.id.editText3);
execute(editText1.getText().toString(),editText2.getText().toString(),editText3.getText().toString());
}
}
}
は、他の問題があるだけでなく、あなたのエラーログ –