【发布时间】:2021-05-24 21:04:45
【问题描述】:
运行应用程序后出现错误,在这一行中
String string=response.getString("url");
Android 工作室要求我创建一个 try and catch mtd,但这不起作用。正确的方法是什么?
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private void loadMeme() {
JSONObject obj = new JSONObject();
RequestQueue queue = Volley.newRequestQueue(this);
String url = "https://meme-api.herokuapp.com/gimme";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, null,
new Response.Listener < JSONObject > () {
@Override
public void onResponse(JSONObject response) {
String string = response.getString("url");
ImageView imageView = (ImageView) findViewById(R.id.shareImageView);
Glide.with(MainActivity.this).load(url).into(imageView);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
// Add the request to the RequestQueue.
queue.add(jsonObjectRequest);
}
【问题讨论】:
标签: java android json android-glide