我正在使用yahoo API进行Android天气应用程序并获取错误。有谁知道这个错误意味着什么?
07-28 20:04:23.958: W/dalvikvm(1303): threadid=1: thread exiting with uncaught exception (group=0x2bd39930)
07-28 20:04:23.958: E/AndroidRuntime(1303): FATAL EXCEPTION: main
07-28 20:04:23.958: E/AndroidRuntime(1303): java.lang.NullPointerException
07-28 20:04:23.958: E/AndroidRuntime(1303): at com.sagar.finalweather.MainActivity.serviceSuccess(MainActivity.java:56)
07-28 20:04:23.958: E/AndroidRuntime(1303): at com.sagar.finalweather.service.YahooWeatherService$1.onPostExecute(YahooWeatherService.java:84)
07-28 20:04:23.958: E/AndroidRuntime(1303): at com.sagar.finalweather.service.YahooWeatherService$1.onPostExecute(YahooWeatherService.java:1)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.os.AsyncTask.finish(AsyncTask.java:631)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.os.AsyncTask.access$600(AsyncTask.java:177)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.os.Handler.dispatchMessage(Handler.java:99)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.os.Looper.loop(Looper.java:137)
07-28 20:04:23.958: E/AndroidRuntime(1303): at android.app.ActivityThread.main(ActivityThread.java:5039)
07-28 20:04:23.958: E/AndroidRuntime(1303): at java.lang.reflect.Method.invokeNative(Native Method)
07-28 20:04:23.958: E/AndroidRuntime(1303): at java.lang.reflect.Method.invoke(Method.java:511)
07-28 20:04:23.958: E/AndroidRuntime(1303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-28 20:04:23.958: E/AndroidRuntime(1303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-28 20:04:23.958: E/AndroidRuntime(1303): at dalvik.system.NativeStart.main(Native Method)
07-28 20:04:27.148: I/Process(1303): Sending signal. PID: 1303 SIG: 9
它是" mainActivity.java"文件请帮我找到确切的错误。我是新的程序员。
package com.sagar.finalweather;
import android.app.Activity;
import android.app.ProgressDialog;
import com.sagar.finalweather.data.Item;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.sagar.finalweather.data.Channel;
import com.sagar.finalweather.service.WeatherServiceCallback;
import com.sagar.finalweather.service.YahooWeatherService;
public class MainActivity extends Activity implements WeatherServiceCallback
{
private ImageView weatherIconImageView;
private TextView temperatureTextView;
private TextView conditionTextView;
private TextView locationTextView;
private ProgressDialog dialog;
private YahooWeatherService service;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
weatherIconImageView = (ImageView)findViewById(R.id.weatherIconImageView);
temperatureTextView = (TextView)findViewById(R.id.LocationTextView);
temperatureTextView = (TextView)findViewById(R.id.TemperatureTextView);
temperatureTextView = (TextView)findViewById(R.id.conditionTextView);
try{
service = new YahooWeatherService(this);
dialog=new ProgressDialog(this);
dialog.setMessage("Loading.......");
dialog.show();
service.refreshWeather("Austin , TX");
}catch(Exception e)
{
e.getMessage();
}
}
@Override
public void serviceSuccess(Channel channel) {
// TODO Auto-generated method stub
dialog.hide();
Item item = channel.getItem();
int resourceId = getResources().getIdentifier("drawable/value_"+item.getCondition().getCode(), null, getPackageName());
Drawable weatherIconDrawable = getResources().getDrawable(resourceId);
weatherIconImageView.setImageDrawable(weatherIconDrawable);
temperatureTextView.setText(item.getCondition().getTemperature()+ "\u00B0" + channel.getUnits().getTemperature());
conditionTextView.setText(item.getCondition().getDescription());
locationTextView.setText(service.getLocation());
}
@Override
public void serviceFailure(Exception exception) {
// TODO Auto-generated method stub
dialog.hide();
Toast.makeText(this, exception.getMessage(), Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:0)
我想是你想要关闭的对话:
dialog.hide();
尚未在onCreate()方法中创建更改此
try{
service = new YahooWeatherService(this);
dialog=new ProgressDialog(this);
dialog.setMessage("Loading.......");
dialog.show();
service.refreshWeather("Austin , TX");
}
到此:
dialog=new ProgressDialog(this);
dialog.setMessage("Loading.......");
dialog.show();
try{
service = new YahooWeatherService(this);
service.refreshWeather("Austin , TX");
}