-1

My code is like this

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());        
    }
}

I am getting exception a toast and log cat shows

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.manager/com.example.manager.MainActivity}:
java.lang.NullPointerException: println needs a message
Cœur
  • 37,241
  • 25
  • 195
  • 267
Siva
  • 9,043
  • 12
  • 40
  • 63

3 Answers3

2

Instead of

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

Put :

Toast.makeText(context, "Database is open", Toast.LENGTH_LONG).show();
Alexis C.
  • 91,686
  • 21
  • 171
  • 177
1

Replace this

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

to this

 Toast toast = Toast.makeText(context, "Database is open", Toast.LENGTH_LONG);
 toast.show();
jimpanzer
  • 3,470
  • 4
  • 44
  • 84
0

@siva Toast.makeText has first parameter for Contex(android.content) which can be your created context in the application. Sometimes getApplicationContext(),getBasecontext() is also generally used,second parameter is for String, third parameter is for duration

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

and stackoverflow.com/questions/3572463/what-is-context-in-android as posted by ZouZou

ashishdhiman2007
  • 807
  • 2
  • 13
  • 28