我无法从表单

时间:2018-04-23 16:33:34

标签: java

我正在尝试使用android studio中的databaseHelper从我的应用程序表单创建数据到数据库。但我不断收到错误。当我检查我的logcat时,这是我看到的代码:

  

进程:com.mysite.appName,PID:17995                                                                       java.lang.IllegalStateException:无法执行方法   安卓的onClick                                                                           在android.view.View $ DeclaredOnClickListener.onClick(View.java:4725)                                                                           在android.view.View.performClick(View.java:5637)                                                                           在android.view.View $ PerformClick.run(View.java:22429)                                                                           在android.os.Handler.handleCallback(Handler.java:751)                                                                           在android.os.Handler.dispatchMessage(Handler.java:95)                                                                           在android.os.Looper.loop(Looper.java:154)                                                                           在android.app.ActivityThread.main(ActivityThread.java:6119)                                                                           at java.lang.reflect.Method.invoke(Native Method)                                                                           在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                        引起:java.lang.reflect.InvocationTargetException                                                                           at java.lang.reflect.Method.invoke(Native Method)                                                                           在android.view.View $ DeclaredOnClickListener.onClick(View.java:4720)                                                                           在android.view.View.performClick(View.java:5637)                                                                           在android.view.View $ PerformClick.run(View.java:22429)                                                                           在android.os.Handler.handleCallback(Handler.java:751)                                                                           在android.os.Handler.dispatchMessage(Handler.java:95)                                                                           在android.os.Looper.loop(Looper.java:154)                                                                           在android.app.ActivityThread.main(ActivityThread.java:6119)                                                                           at java.lang.reflect.Method.invoke(Native Method)                                                                           在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)                                                                           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)                                                                        引起:android.database.sqlite.SQLiteException:靠近“firstName”:   语法错误(代码1):,编译时:创建表用户(id   整数主键不为null firstName文本不为null,lastName文本   不为空,电子邮件文本不为空,电话文本不为空,密码文本不为空   空值);                                                                           在   android.database.sqlite.SQLiteConnection.nativePrepareStatement(母语   方法)                                                                           在   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)

1 个答案:

答案 0 :(得分:0)

您的问题的答案是在logcat的底部,其中显示Caused by: android.database.sqlite.SQLiteException: near "firstName":

然后继续列出它无法编译的SQL语句:

create table users (id integer primary key not null firstName text not null, lastName text not null, email text not null, phone text not null, password text not null);

id integer primary key not null之后,您的创建表语句中似乎缺少逗号。