I have a question for Android Volley.

Asked 1 years ago, Updated 1 years ago, 130 views

public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
TextView tv;
String url;
StringRequest stringRequest;
String data;
public static RequestQueue requestQueue;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tv = findViewById(R.id.tv);

    url = "http://openapi.airkorea.or.kr/openapi/services/rest/MsrstnInfoInqireSvc/getNearbyMsrstnList?tmX=244148.546388&tmY=412423.75772&pageNo=1&numOfRows=10&ServiceKey=P7D382pxAC1BmoMRsbrVGYmWh%2FvoZ4HQsAf5Z%2BsPAyWlVUpe178UHS%2BekKoLR2k%2Bo7V5B5lZV71p8fIMMBiHAQ%3D%3D&_returnType=json";
    if (requestQueue == null) {
        requestQueue = Volley.newRequestQueue(getApplicationContext());
    }
    responseVolley(url);
    Toast.makeText(this, data, Toast.LENGTH_SHORT).show();
}

public void responseVolley(String url){
    String result = null;
    stringRequest = new StringRequest(
            com.android.volley.Request.Method.GET
            , , url
            , , new com.android.volley.Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            processResponse(response);
        }
    }, }, new com.android.volley.Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("volleyError", error.getMessage());
        }
    }
    );
    stringRequest.setShouldCache(false);
    requestQueue.add(stringRequest);


    return;
}

public void processResponse(String response){
    Gson gson = new Gson();
    DustList dustList = gson.fromJson(response, DustList.class);
    list lists = dustList.list.get(0);
    data = lists.stationName;
    Log.d("onResponse", data);
    println(data);

}

public void println(String sta) {
    tv.setText(sta);
}
}

Why isn't Gson data in String data? It's null even if I print Toast...

volley gson parsing

2022-09-22 18:55

1 Answers

When I called the URL, INVALID PARAMETER ERROR occurred, but I don't think I received the correct response.


2022-09-22 18:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.