調用實例方法在預定義的I類有兩個類,如下圖所示:如何從另一個類中的Android
TestActivity.java
public class TextActivity extends Activity {
public void onCreate(Bundle savedinsstate) {
super.onCreate(savedinsstate);
Intent intent=new Intent(this,MYMapActivity.class);
startActivity(intent);
MYMapActivity.ma.displayGoogleMaps();
}
}
MYMapActivity.java
public class MYMapActivity extends MapActivity {
public static MYMapActivity ma;
public void onCreate(Bundle savedinsstate) {
super.onCreate(savedinsstate);
ma=this;
}
public void displayGoogleMaps(){
//some code here.
}
}
從上面的時候我打電話給MYMapActivity.ma.displayGoogleMaps()我很難得到NullPointerException。我已經調試了代碼,然後最終我發現,代替馬我得到空。我該如何解決這個問題?