object 的内部即开始标签(start tag)”” 和“
public class MainActivity9 extends AppCompatActivity { private Handler handler=new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main9); ImageView iv=findViewById(R.id.iv); Button bt2=findViewById(R.id.bt2); bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new Thread(new Runnable() { @Override public void run() { try { URL url=new URL("http://43.143.146.165:7777/foods/getFoods?currentPage=1&pageSize=12"); HttpURLConnection connection= (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(15000); connection.setReadTimeout(15000); connection.connect(); if (connection.getResponseCode()==200){ InputStream is=connection.getInputStream(); Bitmap bitmap= BitmapFactory.decodeStream(is); handler.post(new Runnable() { @Override public void run() { iv.setImageBitmap(bitmap); } }); is.close(); } } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }).start(); } }); Button bt=findViewById(R.id.bt); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new Thread(new Runnable() { @Override public void run() { try { URL url=new URL("http://43.143.146.165:7777/foods/getFoods?currentPage=1&pageSize=12"); HttpURLConnection connection= (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); connection.setDoOutput(true); connection.connect(); String data="username=123&password=123"; connection.getOutputStream().write(data.getBytes()); if (connection.getResponseCode()==200){ InputStream is=connection.getInputStream(); BufferedReader br=new BufferedReader(new InputStreamReader(is)); StringBuilder sb=new StringBuilder(); String line=null; while ((line=br.readLine())!=null){ sb.append(line); } JsonResult jr=new Gson().fromJson(sb.toString(),JsonResult.class); System.out.println(jr.getMessage()+"-"+jr.getCode()); } } catch (MalformedURLException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } }).start(); } }); } }