我知道,这个问题之前曾提出过,但我无法超越。我想定义全局变量,所以我使用了扩展application class
。但我无法达到此subclass
。
我也创建了公共构造函数。
我的superclass
和subclass
在这里:
class GlobalVariables extends Application {
private int sessionid;
private Locale locale;
public GlobalVariables(){
}
public int getSessionid() {
return sessionid;
}
public void setSessionid(int sessionid) {
this.sessionid = sessionid;
}
public Locale getLocale() {
return locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
}
class Application extends Activity {
Intent intent;
int sessionid;
Log log = new Log();
SQLiteDatabase db2;
GeneralLog db = new GeneralLog(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sessionid = getSessionId()+1;
GlobalVariables glb = new GlobalVariables();
glb.setSessionid(sessionid);
setContentView(R.layout.application);
}
public int getSessionId() {
SQLiteDatabase db2 = db.getReadableDatabase();
final SQLiteStatement stmt = db2.compileStatement("SELECT MAX(sessionid) FROM LOG2");
return (int) stmt.simpleQueryForLong();
}
public Application() {
}
}
我收到此错误:
java.lang.IllegalAccessException : access the class not allowed
最佳答案
扩展Application
的类必须为public
public class GlobalVariables extends Application
关于java - 如何允许访问类(class)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14932604/