Bebo February 2016

Error: Unfortunately App has stopped

I am trying to create a create an account form through SQLITE database but when I try to run on phone or Emulator it shows "Unfortunately APP has stopped" .

this is my Mnifest File code

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

this is my MainActivity

public class MainActivity extends AppCompatActivity {

DatabaseHelper myDb;

EditText editName, editPassword, editEmail;

Button buttonRegister;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myDb=new DatabaseHelper(this);

    editName = (EditText) findViewById(R.id.edit_name);
    editEmail = (EditText) findViewById(R.id.edit_email);

    editPassword = (EditText) findViewById(R.id.edit_password);

    buttonRegister = (Button) findViewById(R.id.ButtonRegister);

    Reg();
}

public void Reg(){
    buttonRegister.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    boolean isInserted=myDb.insertData(editName.getText().toString(),
                            editEmail.getText().toString(),
                            editPassword.getText().toString());
                    if(isInserted==true)
                         

Answers


Dalma Racz February 2016

In DatabaseHelper onCreate() you are missing 2 spaces (before and after table name):

db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, PASS TEXT)");


xUser February 2016

You should add spaces before and after table name like "create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, PASS TEXT)"


Rohit5k2 February 2016

Forgot to add a space before and after table name.

Change

 db.execSQL("create table" + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, PASS TEXT)");

to

 db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, PASS TEXT)");


Moudiz February 2016

change to like this (add space )

public void onCreate(SQLiteDatabase db) {
    db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, EMAIL TEXT, PASS TEXT)");

}

also dont forget to fix this too , ( add space after exist)

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXIST "+TABLE_NAME);
    onCreate(db);

}

Post Status

Asked in February 2016
Viewed 2,539 times
Voted 8
Answered 4 times

Search




Leave an answer