java - My application crashes while trying to use Volley
问题描述
I try to capture data using a volley, but my application crashes. the application opens but my application crashes when I press the search button.
public class MainActivity extends AppCompatActivity {
TextView tvYear,tvDirector,tvActor,tvLanguage,tvPlots,tvCountry;
ImageView ivPoster;
EditText edName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edName = findViewById(R.id.edName);
tvYear = findViewById(R.id.tvYear);
}
public void search(View view) {
String mName = edName.getText().toString();
if(mName.isEmpty())
{
edName.setError("please provide movie name");
return;
}
String url = "HTTP://www.omdbapi.com/?t="+mName+"&plot=full&apikey=myApiKey";
RequestQueue queue = Volley.newRequestQueue(this);
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject movie = new JSONObject(response);
String result = movie.getString("Response");
right there crash app----> tvYear.setText(result);
if(result.equals("True"))
{
Toast.makeText(MainActivity.this, "Found", Toast.LENGTH_SHORT).show();
if(posterUrl.equals("N/A"))
{
}
else
{
}
}
else
{
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
queue.add(request);
}
my application crashes right here
tvYear.setText(result);
my application doesn't crash when I delete this line. I want to see the value of requestin but it crashes
解决方案
您可以在每一行之后打印日志以查看变量的值。请指出究竟是什么日志猫显示错误?
推荐阅读
- unity3d - RayCast2D 忽略击中自己的 Collider
- android - Android:不能在 SD 卡上 mkdir
- javascript - 似乎无法用 JS 或 jQuery 关闭以前打开的元素
- javascript - 无法通过自定义快速验证器检查
- javascript - 在 for 循环中生成的重复表单没有获得所需的值
- virtualbox - 相同的 tshark 版本错过了其他机器中的 http2 解码
- azure-logic-apps - How to loop and extract items from Nested Json Array in Logic Apps
- android - 在android上更新通知有时不会更新
- javascript - 在 redux reducer 和 actions 中编写相同的函数行为
- perl - Perl 连接到 Google Cloud MySQL 不工作