I'm trying do re-adapt simple weather app (http://code.tutsplus.com/tutorials/create-a-weather-app-on-android--cms-21587) to Google Glass, it returns a json object on Android and works, but in my google glass when I want to use the getCity function, I have a null pointer exception error.
My getCity function is the same as the one in SimpleWeatherApp
public String getCity(){
return prefs.getString("city", "Jerusalem, IL");
}
Theres is 3 Java Files, 2 Class and 1 Activity.
Citypreference , to return the city and get city.
RemoteFetch to get the Json Object
Main activity to build view for the google glass and show the information that I need.
I can share to you the whole project if you want more informations.
here's a part of my MainActivity content private View buildView() { CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT); card.setText(R.string.open_weather_maps_app_id); //updateWeatherData(new CityPreference(getActivity()).getCity());
updateWeatherData(new CityPreference().getCity());
return card.getView();
}
private void updateWeatherData(final String city){
new Thread(){
public void run(){
final JSONObject json = RemoteFetch.getJSON(MainActivity.this.getApplicationContext(),city);
if(json == null){
handler.post(new Runnable(){
public void run(){
Toast.makeText(MainActivity.this,
MainActivity.this.getString(R.string.place_not_found), = SO JSON NULL
Toast.LENGTH_LONG).show();
}
});
} else {
handler.post(new Runnable(){
public void run(){
renderWeather(json);
}
});
}
}
}.start();
}
So that's mean my json object is null. For the remotefetch.java you can find it in the SimpleWeatherApp link on the top of my post