问题描述
- 列表视图中传递int值到string值
-
TextView location=(TextView)template_view.findViewById(R.id.tvlocation); TextView weather=(TextView)template_view.findViewById(R.id.tvweather); TextView temp=(TextView)template_view.findViewById(R.id.tvtemp); TextView dewpoint=(TextView)template_view.findViewById(R.id.tvdew); TextView humidity=(TextView)template_view.findViewById(R.id.tvhumidity); TextView windspeed=(TextView)template_view.findViewById(R.id.tvspeed); TextView winddir=(TextView)template_view.findViewById(R.id.tvdir); TextView windgust=(TextView)template_view.findViewById(R.id.tvgust); TextView pressure=(TextView)template_view.findViewById(R.id.tvcondition); TextView heatindex=(TextView)template_view.findViewById(R.id.tvheat); TextView visibility=(TextView)template_view.findViewById(R.id.tvvisibility); TextView precipitation=(TextView)template_view.findViewById(R.id.tvprecipitation); TextView dailyprecipitation=(TextView)template_view.findViewById(R.id.tvdaily); TextView sunrise=(TextView)template_view.findViewById(R.id.tvsunrise); TextView sunset=(TextView)template_view.findViewById(R.id.tvsunset); location.setText(Voicenames.get(position).getLocation()); weather.setText(Voicenames.get(position).getWeather()); //temp.setText(Voicenames.get(position).getTemp_c()); //dewpoint.setText(Voicenames.get(position).getDewpoint_c()); //windspeed.setText(Voicenames.get(position).getWind_kph()); //windgust.setText(Voicenames.get(position).getWind_gust_kph()); humidity.setText(Voicenames.get(position).getRelative_humidity()); winddir.setText(Voicenames.get(position).getWind_dir()); pressure.setText(Voicenames.get(position).getPressure_mb()); heatindex.setText(Voicenames.get(position).getHeat_index_c()); visibility.setText(Voicenames.get(position).getVisibility_km()); precipitation.setText(Voicenames.get(position).getPrecipitation()); dailyprecipitation.setText(Voicenames.get(position).getDaily_precipitation()); sunrise.setText(Voicenames.get(position).getSunrise()); sunset.setText(Voicenames.get(position).getSunset());
有一个全是string值的列表视图。我将注释放到int值中,然后将int值传递过去,但是总是报出空指针异常。应该怎么解决?
我用到JSONboject。
解决方案
我找到的实现方法:String.valueOf(Voicenames.get(position).getWhatever());
解决方案二:
把具体相关的代码贴出来,不然没有会回答你的问题的, 因为看不懂
时间: 2024-10-31 14:13:30