-1

我的代码是这样的

public Database(Context context) {
    super(context, dbname, null, dbversion);
    try{
      db=getWritableDatabase();
      // TODO Auto-generated constructor stub
      if (db.isOpen()){
        Toast.makeText(null, "Database is open", Toast.LENGTH_LONG).show();
      } else {      
        Toast.makeText(null, "Database is Closed", Toast.LENGTH_LONG).show();
      }
    } catch(Exception e) {
      Log.e(dbname, e.getMessage());        
    }
}

我收到异常祝酒和日志猫节目

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.manager/com.example.manager.MainActivity}:
java.lang.NullPointerException: println needs a message
4

3 回答 3

2

代替

Toast.makeText(null, "Database is open", Toast.LENGTH_LONG).show();

放 :

Toast.makeText(context, "Database is open", Toast.LENGTH_LONG).show();
于 2013-04-24T14:48:30.240 回答
1

替换这个

 Toast.makeText(null, "Database is open", Toast.LENGTH_LONG).show();

对此

 Toast toast = Toast.makeText(context, "Database is open", Toast.LENGTH_LONG);
 toast.show();
于 2013-04-24T14:49:28.697 回答
0

@siva Toast.makeText 具有 Contex(android.content) 的第一个参数,它可以是您在应用程序中创建的上下文。有时getApplicationContext(),getBasecontext()也一般用,第二个参数是String,第三个参数是duration

http://developer.android.com/guide/topics/ui/notifiers/toasts.html

ZouZou 发布的 stackoverflow.com/questions/3572463/what-is-context-in-android

于 2013-04-24T14:59:50.807 回答