Home > Mobile >  Help!!!!!! How can create android database!!!!!!
Help!!!!!! How can create android database!!!!!!

Time:09-25

When creating unable to create success, can't see this table in DDMS, when inserted into the display null pointer
 public myhelper Context (Context) {
Super (context, "itcast. Db", null, 1);
//TODO Auto - generated constructor stub
}

@ Override
Public void onCreate (SQLiteDatabase db) {
//TODO Auto - generated method stub
Db. ExecSQL (" create table information (_id integer primary key autoincrement, name varchar (20), price, integer) ");
Db. ExecSQL (" insert into information (name, price) values (?,?,?,?,? ,?) The new object [] {' a ', '6'} ");

}

 
Myhelper. GetReadableDatabase ();
Myhelper. GetWritableDatabase ();


Display error
 
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : FATAL EXCEPTION: the main
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : the Process: com. Example. Qaq, PID: 22971
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : Java. Lang. RuntimeException: Unable to start the activity ComponentInfo {com. Example. Qaq/com. Example. Qaq. MainActivity} : Java. Lang. NullPointerException: Attempt to invoke virtual method 'android. Database. Sqlite. SQLiteDatabase com. Example. Qaq. Myhelper. GetReadableDatabase ()' on a null object reference
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2325)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2387)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread. Access the $800 (151) ActivityThread. Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread $H.h andleMessage (ActivityThread. Java: 1303)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The OS. Handler. DispatchMessage (Handler. Java: 102)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The OS. Stars. Loop (135). Which Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread. Main (5254) ActivityThread. Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : at the Java. Lang. Reflect. Method. Invoke (Native Method)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : at the Java. Lang. Reflect. Method. Invoke (372) Method. The Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : at the android. Internal. OS. $MethodAndArgsCaller ZygoteInit. Run (ZygoteInit. Java: 903)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : at the android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 698)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : under Caused by: Java. Lang. NullPointerException: Attempt to invoke virtual method 'android. Database. Sqlite. SQLiteDatabase com. Example. Qaq. Myhelper. GetReadableDatabase ()' on a null object reference
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : the at com. Example. Qaq. MainActivity. OnCreate (MainActivity. Java: 15)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. Activity. PerformCreate (5990) Activity. Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. Instrumentation. CallActivityOnCreate (1106) Instrumentation. Java:
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) : an android. The app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2278)
12 to 28 12:58:30. 440: E/AndroidRuntime (22971) :... 10 more


Less instantiation
 12 to 28 12:58:03. 540: E/SQLiteLog (22708) : (1) near the "new" : syntax error 



CodePudding user response:

Itcast. Db database file exist?
When you confirm this to run the program, called onCreate?

CodePudding user response:

reference 1st floor jzp12 response:
itcast. Db database file exist?
When you confirm this to run the program, called onCreate?

Itcast all have no,,,,

CodePudding user response:

It's convenient, would direct messages, I send my project to see,

CodePudding user response:

You must first create a Myhelper object to invoke the member function
SQLiteDatabase db=myhelper. GetWritableDatabase ();
Add in front of the myhelper=new myhelper (this);

CodePudding user response:

To review your first returns to learn JAVA
Basic not firm, shaking

CodePudding user response:

Surprise!!!!!!!!!!! I thought that is on the main function,!!!!!!!!!! I, thanks to the eldest brother!!!!!!!!!!!
  • Related