안녕 내 안드로이드 프로젝트는GET 값은
는 위도와 경도을 제공- GPSTracker.java 클래스는 ADRESS API에서 JSON을 얻을
- RemoteFetch.java 클래스는 입니다 입니다 정적 상태에
MainActivity.java 하지만 JSON을 얻을 수있는 URL은 같다 :
개인 정적 최종 문자열 OPEN_WEATHER_MAP_API = "http://api.openweathermap.org/data/2.5/weather? " + "q = % s &"+ "lat ="+ "& lon ="+ "& 단위 = 미터법";
내 위도와 경도가 GPSTracker에 있지만, 나는 그들을 받고 있어요 때 그들이 정적 형식이 아닌 것 같은 날이 값을 가지 않도록 ...
그래서 내가 openweatherapi URL에 오류를 추가하자마자 오류가 발생합니다.
"정적 필드가 아닌 정적 필드는 정적 컨텍스트에서 참조 할 수 없습니다."
문자열/int 형식을 정적 형식으로 "캐스팅"할 수있는 방법이 있습니까 ??
더 많은 정보가 필요하면 제발 저에게하십시오. 여기
RemoteFetch.java에서 일부 코드
private void updateWeatherData(final String city){
new Thread(){
public void run(){
final JSONObject json = RemoteFetch.getJSON(MainActivity.this,city);
if(json == null){
handler.post(new Runnable(){
public void run(){
Toast.makeText(MainActivity.this.getApplicationContext(),R.string.place_not_found,Toast.LENGTH_LONG).show();
}
});
} else {
handler.post(new Runnable(){
public void run(){
renderWeather(json);
}
});
}
}
}.start();
}
private static final String OPEN_WEATHER_MAP_API =
"http://api.openweathermap.org/data/2.5/weather?" + "q=%s&" +"lat="+"&lon=" + "&units=metric";
public static JSONObject getJSON(Context context, String city){
try {
// gps.getLatitude();
URL url = new URL(String.format(OPEN_WEATHER_MAP_API, city));
HttpURLConnection connection =
(HttpURLConnection)url.openConnection();
connection.addRequestProperty("x-api-key",
context.getString(R.string.open_weather_maps_app_id));
BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
StringBuffer json = new StringBuffer(1024);
String tmp="";
while((tmp=reader.readLine())!=null)
json.append(tmp).append("\n");
reader.close();
JSONObject data = new JSONObject(json.toString());
GPSTracker 클래스 가져 오기 좌표 메서드를 정적으로 변경할 수 있습니까? – Xcihnegn