2010-01-18 320 views
0

我想在android模擬器上運行應用程序,但它崩潰。我正在關注howtoAndroid應用程序崩潰

我不知道該怎麼做,它只是崩潰。其他應用程序正在運行的罰款,任何人都可以告訴我,我在做什麼wrong.here是代碼:

public class Finder extends Activity { 
    /** Called when the activity is first created. */ 
private LocationManager myLocationManager; 
private LocationListener myLocationListener; 
private TextView myLatitude, myLongitude; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    myLatitude = (TextView)findViewById(R.id.Latitude); 
    myLongitude = (TextView)findViewById(R.id.Longitude); 


    myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
    myLocationListener = new MyLocationListener(); 
    myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myLocationListener); 
    myLatitude.setText(String.valueOf(
     myLocationManager.getLastKnownLocation(
      LocationManager.GPS_PROVIDER).getLatitude())); 

     myLongitude.setText(String.valueOf(
     myLocationManager.getLastKnownLocation(
     LocationManager.GPS_PROVIDER).getLongitude())); 
} 
private class MyLocationListener implements LocationListener{ 

public void onLocationChanged(Location argLocation) { 
// TODO Auto-generated method stub 
myLatitude.setText(String.valueOf(
    argLocation.getLatitude())); 
myLongitude.setText(String.valueOf(
    argLocation.getLongitude())); 
} 

public void onProviderDisabled(String provider) { 
// TODO Auto-generated method stub 
} 

public void onProviderEnabled(String provider) { 
// TODO Auto-generated method stub 
} 

public void onStatusChanged(String provider, 
    int status, Bundle extras) { 
// TODO Auto-generated method stub 
} 
}; 

}

我看着在logcat中運行的應用程序後,似乎下面的行這個問題的原因,但我不明白它:(

01-18 22:12:46.017: WARN/dalvikvm(1091): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 
01-18 22:12:46.017: ERROR/AndroidRuntime(1091): Uncaught handler: thread main exiting due to uncaught exception 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091): java.lang.RuntimeException: Unable to start activity ComponentInfo{pro.googleLocation/pro.googleLocation.Finder}: java.lang.NullPointerException 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread.access$2100(ActivityThread.java:116) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.os.Handler.dispatchMessage(Handler.java:99) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.os.Looper.loop(Looper.java:123) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread.main(ActivityThread.java:4203) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at java.lang.reflect.Method.invokeNative(Native Method) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at java.lang.reflect.Method.invoke(Method.java:521) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at dalvik.system.NativeStart.main(Native Method) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091): Caused by: java.lang.NullPointerException 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at pro.googleLocation.Finder.onCreate(Finder.java:28) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 
01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  ... 11 more 
+1

你需要看一下Java堆棧跟蹤以查找源的崩潰。您可以通過'adb logcat',DDMS或Eclipse中的DDMS透視圖來訪問它。如果您不瞭解例外情況,請編輯您的問題並在此處發佈堆棧跟蹤。 – CommonsWare 2010-01-18 21:09:45

+0

Finder.java的第28行究竟是哪一行? – 2010-01-18 21:30:05

+0

您是否記得將活動添加到清單中? – RickNotFred 2010-01-18 22:05:23

回答

0

是不是從你的日誌清楚了嗎?

01-18 22:12:46.037: ERROR/AndroidRuntime(1091):  at pro.googleLocation.Finder.onCreate(Finder.java:28) 

無論是在線28上拋出一個NullPointerException,找到該行,找到問題。

-1

好了,我找到了解決辦法:) 我幾乎忘了通過GPS座標模擬器,這樣做與工作完美:)