我尝试为我的学习创建一个应用程序,它是一个跟踪运动。
当我发送新的本地化时,我的应用程序由于此错误而崩溃:
03-18 18:44:34.662: E/AndroidRuntime(1085): FATAL EXCEPTION: main
03-18 18:44:34.662: E/AndroidRuntime(1085): java.lang.NullPointerException
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.app.Activity.findViewById(Activity.java:1839)
03-18 18:44:34.662: E/AndroidRuntime(1085): at fr.polytech.trackersportif.GPSData.onLocationChanged(GPSData.java:28)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:255)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.location.LocationManager$ListenerTransport.access$000(LocationManager.java:184)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:200)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.os.Looper.loop(Looper.java:137)
03-18 18:44:34.662: E/AndroidRuntime(1085): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-18 18:44:34.662: E/AndroidRuntime(1085): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 18:44:34.662: E/AndroidRuntime(1085): at java.lang.reflect.Method.invoke(Method.java:511)
03-18 18:44:34.662: E/AndroidRuntime(1085): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-18 18:44:34.662: E/AndroidRuntime(1085): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-18 18:44:34.662: E/AndroidRuntime(1085): at dalvik.system.NativeStart.main(Native Method)
我的主要活动是:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationListener = new GPSData();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, locationListener);
完成我的课程(GPSData)是:
public class GPSData extends Activity implements LocationListener{
TextView textLong, textLat;
protected void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
setContentView(R.layout.page_accueil); //page_acceuil is the layout where are the two textview that I want set text
}
@Override
public void onLocationChanged(Location location) {
textLong = (TextView) findViewById(R.id.textView1);
textLat = (TextView) findViewById(R.id.textView3);
textLong.setText(String.valueOf(location.getLongitude()));
textLat.setText(String.valueOf(location.getLatitude()));
}
两天后我尝试了不同的事情,但我一次又一次地遇到这个错误。
你能帮我吗?