开发者

Android Application Crashes

i am trying to run an application on an android emulator, but it crashes. i am following a howto

i don't know what to do, it just crashes. other applications are running fine, can anyone tell me what i am doing wrong.here is the code:

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 stu开发者_如何学Pythonb
 }
 };

}

i looked in the logcat after running the application, it seems that the following lines are cause of the problem but i don't understand it:(

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


Isn't it clear from your log ?

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

whatever it's on line 28 is throwing a NullPointerException, find that line, find the problem.


ok, so i found the solution:) i was forgetting to pass gps coordinates to the emulator,did that and worked perfectly:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜