开发者

Call a non static methode in a static SQLiteDatabase class

开发者 https://www.devze.com 2022-12-24 22:45 出处:网络
i want to display a msg to the user (msg box or Toast) when exception happend in a static SQLite Database class that i use.

i want to display a msg to the user (msg box or Toast) when exception happend in a static SQLite Database class that i use.

the problem is that i cant call a non static method in a static class , how can i handle this.

this is the class

private static SQLiteDatabase getDatabase(Context aContext) {

and i want to a开发者_运维百科dd something like this in the class when exception happen but context generates the problem of reference to non static in static class.

Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();


It sounds like you're trying to use the "getApplicationContext()" function, which is a nonstatic method. You can't call nonstatic methods from static ones. Why don't you just use the context that is passed in? i.e.,

Context context = aContext;
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;

Toast toast = Toast.makeText(context, text, duration);
toast.show();
0

精彩评论

暂无评论...
验证码 换一张
取 消