다음과 같은 사용자 정의 글로벌 클래스가 있습니다.
import android.app.Application;
public class MyApp extends Application {
public String MainAct;
public String getMainAct() {
return MainAct;
}
public void setMainAct(String mainAct) {
MainAct = mainAct;
}
}
메서드 Activity에서 다른 클래스를 통해이 클래스의 문자열을 유지하고 싶습니다 onCreate.
String local = "myLocalVariable";
((MyApp) getApplication()).setMainAct(local); //breaks here!!!
String name = ((MyApp) getApplication()).getMainAct();
표시된 줄에서 오류가 발생하여 중단됩니다. Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.xxx.yyy.global.MyApp
코드를 다섯 번 확인했는데 어디서나 오류를 찾을 수 없습니다. 누구든지 오류가 어디 있는지 말해 줄 수 있습니까?!
감사