我试图通过保存应用程序上下文的位置,所以我做了以下内容:的Android getApplicationContext NullPointerException异常
对myApp类:
进口android.app.Application;
import com.google.android.maps.GeoPoint;
public class myApp extends Application {
private GeoPoint Tunis = new GeoPoint(microdegrees(36.827589),microdegrees(10.171165));
private GeoPoint myLocation=Tunis;
public GeoPoint getMyLocation(){
return myLocation;
}
public void setMyLocation(GeoPoint s){
myLocation = s;
}
private int microdegrees(double value){
return (int)(value*1000000);
}
}
我的清单:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name=".myApp">
<uses-library android:name="com.google.android.maps"/>
<activity android:name=".Main"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
,在我的主要活动我这样做:
myApp appState = ((myApp)getApplicationContext());
,这将导致一个NullPointerException当我启动应用程序:(可以请你告诉我为什么会发生这种异常?我认为在myApp类中,我将MyLocation初始化为现有的GeoPoint?
个谢谢,
没有更多的源代码和完整的堆栈跟踪,没有人可以帮助你。 – CommonsWare 2011-01-09 13:36:08