smartF smartF - 1 year ago 208
Java Question

E/AndroidRuntime: FATAL EXCEPTION: main (main Register issue)

While Testing my app i got this error. And i am unable to resolve this as i am newbee in Java

E/SQLiteLog: (1) near "tableRegister": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main

Process: tweeteve1.loginregister, PID: 3348
android.database.sqlite.SQLiteException: near "tableRegister": syntax error (code 1): , while compiling: create tableRegister(user_id integer primary key autoincrement, Name text, UserName text, Password text, Age int)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(
at android.database.sqlite.SQLiteConnection.prepare(
at android.database.sqlite.SQLiteSession.prepare(
at android.database.sqlite.SQLiteProgram.<init>(
at android.database.sqlite.SQLiteStatement.<init>(
at android.database.sqlite.SQLiteDatabase.executeSql(
at android.database.sqlite.SQLiteDatabase.execSQL(
at tweeteve1.loginregister.DatabaseHelper.onCreate(
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(
at tweeteve1.loginregister.DatabaseHelper.insertData(
at tweeteve1.loginregister.Register$1.onClick(
at android.view.View.performClick(
at android.view.View$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)
Application terminated.

my code is here
Register file:

package tweeteve1.loginregister;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.jar.Attributes;

public class Register extends AppCompatActivity {
DatabaseHelper myDB;
EditText ePassword;
EditText eUserName;
EditText eName;
EditText eAge;
Button bRegister;
protected void onCreate(Bundle savedInstanceState) {
myDB = new DatabaseHelper(this);
eAge = (EditText) findViewById(;
eName = (EditText) findViewById(;
eUserName = (EditText) findViewById(;
ePassword = (EditText) findViewById(;
bRegister = (Button) findViewById(;

public void AddData() {
new View.OnClickListener() {
public void onClick(View v) {
boolean isInserted = myDB.insertData(eName.getText().toString(),
if(isInserted == true)
Toast.makeText(Register.this,"Data Inserted",Toast.LENGTH_LONG).show();
Toast.makeText(Register.this,"Data not Inserted",Toast.LENGTH_LONG).show();

Do help me please in solving my problem Thank you

Answer Source

The reason is actually self evident - right in the error message - look at your SQL statement that's being executed:

create tableRegister(user_id integer primary key autoincrement, Name text, UserName text, Password text, Age int)

As you can see, there's a space missing between table and Register. The stack trace is also very helpfully points out that the error is in line 28 of file:

at tweeteve1.loginregister.DatabaseHelper.onCreate(

So, look at class, line 28, and add the missing space.

EDIT: based on the create table code from the comment, change it to be:

db.execSQL("create table " + TableName + " (user_id integer primary key autoincrement, Name text, UserName text, Password text, Age int)");

Note the spaces after table and before (user_id.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download