-1

Hello I try to develop one application based on the SQLiteDatabase. I develop simple code which create database but it's not working in AVD means its crash the application. Please guys help me out.

I post my code and error for that. It is very appreciable.

DatabaseHelper.java

package com.example.bhaumik.sqlitedatabasetest;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Bhaumik on 25-02-2016.
 */
public class DatabaseHelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "Student.db";
    public static final String TABLE_NAME = "student";
    public static final String COLUMN_1 = "ID";
    public static final String COLUMN_2 = "NAME";
    public static final String COLUMN_3 = "SURNAME";



    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
        SQLiteDatabase db = this.getWritableDatabase();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table" + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT)");
        //db.execSQL("create table " + TABLE_NAME +
            //    " (ID INTEGER AUTOINCREMENT , PRODUCT_NAME PRIMARY KEY TEXT , PRODUCT_SIZE INTEGER , PRODUCT_RUPPESS INTEGER , BUY_NUMBER INTEGER)");



    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
}

MainActivity.java

package com.example.bhaumik.sqlitedatabasetest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
    DatabaseHelper mydb ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mydb = new DatabaseHelper(this);

    }
}

Also post an error for that

02-26 00:06:43.030 1898-1898/? E/NetworkScheduler.SchedulerReceiver: Invalid parameter app
02-26 00:06:43.030 1898-1898/? E/NetworkScheduler.SchedulerReceiver: Invalid package name : Perhaps you didn't include a PendingIntent in the extras?


  02-26 07:30:49.886 952-952/? E/lowmemorykiller: Kernel does not support memory pressure events or in-kernel low memory killer
 02-26 07:30:50.575 972-972/? E/perfprofd: unable to open configuration file /data/data/com.google.android.gms/files/perfprofd.conf
 02-26 07:30:51.750 954-954/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
02-26 07:30:54.291 965-965/? E/CameraService: setUpVendorTags: Vendor tag operations not fully defined. Ignoring definitions.
  02-26 07:30:55.845 954-989/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
  02-26 07:30:55.848 1135-1236/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
   02-26 07:30:56.876 961-961/? E/Netd: cannot find interface dummy0
  02-26 07:30:59.643 965-965/? E/SoundTriggerHwService: couldn't load sound trigger module sound_trigger.primary (No such file or directory)
 02-26 07:30:59.643 965-965/? E/RadioService: couldn't load radio module radio.primary (No such file or directory)
    02-26 07:30:59.644 965-1293/? E/AudioFlinger: no wake lock to update!
  02-26 07:31:04.113 970-970/? E/memtrack: Couldn't load memtrack module (No such file or directory)
    02-26 07:31:04.113 970-970/? E/android.os.Debug: failed to load memtrack module: -2
  02-26 07:31:07.698 970-970/? E/Minikin: addFont failed to create font /system/fonts/NanumGothic.ttf
    02-26 07:31:07.698 970-970/? E/Minikin: addFont failed to create font /system/fonts/DroidSansFallback.ttf
    02-26 07:31:07.698 970-970/? E/Minikin: addFont failed to create font /system/fonts/MTLmr3m.ttf
 02-26 07:31:13.573 966-966/? E/installd: eof
    02-26 07:31:13.573 966-966/? E/installd: failed to read size
 02-26 07:31:16.842 1305-1305/? E/art: DexFile_getDexOptNeeded file '/system/framework/org.apache.http.legacy.jar' does not exist
  02-26 07:31:26.749 1305-1305/? E/ConsumerIrService: Can't open consumer IR HW Module, error: -2
02-26 07:31:27.624 1305-1342/? E/EventHub: could not get driver version for /dev/input/mice, Not a typewriter
 02-26 07:31:27.792 954-954/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
  02-26 07:31:33.093 1305-1305/? E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.password.key: open failed: ENOENT (No such file or directory)
    02-26 07:31:33.093 1305-1305/? E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/password.key: open failed: ENOENT (No such file or directory)
    02-26 07:31:33.093 1305-1305/? E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.pattern.key: open failed: ENOENT (No such file or directory)
    02-26 07:31:33.093 1305-1305/? E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gatekeeper.gesture.key: open failed: ENOENT (No such file or directory)
    02-26 07:31:33.093 1305-1305/? E/LockSettingsStorage: Cannot read file java.io.FileNotFoundException: /data/system/gesture.key: open failed: ENOENT (No such file or directory)
JoxTraex
  • 13,423
  • 6
  • 32
  • 45
Bhaumik
  • 11
  • 1
  • 7
  • It create database in the Android Device Monitor – Bhaumik Feb 25 '16 at 18:55
  • 2
    The error you have posted has nothing to do with the code. You need to post the error that your code causes. – Kuffs Feb 25 '16 at 19:18
  • some of error i have updated – Bhaumik Feb 26 '16 at 04:03
  • 1
    Android studio has NOTHING to do with Android code when its running. Android studio is just the place where you write the code, nothing more after that. – JoxTraex Feb 26 '16 at 04:04
  • There is no error in log cat, please learn how to provide proper logs otherwise you can't get help. – JoxTraex Feb 26 '16 at 04:05
  • @JoxTraex Actually, there are a bunch of errors, but nothing related to the current code – OneCricketeer Feb 26 '16 at 04:06
  • When I said "there is no error in logcat" I meant that there is no error that explains why his app crashed. – JoxTraex Feb 26 '16 at 04:07
  • @Bhaumik Since you have not provided useful errors, I would suggest reading about SQLite on Android and getting a "working" tutorial version complete first, then change it to fit your needs. You may find this tutorial useful. http://www.vogella.com/tutorials/AndroidSQLite/article.html – OneCricketeer Feb 26 '16 at 04:10
  • sorry guys I am new in android. So can you help which error you guys want? – Bhaumik Feb 26 '16 at 05:56

2 Answers2

1

You need whitespace between SQL keywords and identifiers such as table names.

Change

"create table" + TABLE_NAME

to

"create table " + TABLE_NAME
laalto
  • 150,114
  • 66
  • 286
  • 303
  • That's an error in the code you posted. Without anything more specific in the question I cannot help you any further. – laalto Feb 26 '16 at 06:09
  • "(ID INTEGER PRIMARY KEY AUTOINCREMENT)") Is there possiblity an error here?? – Bhaumik Feb 26 '16 at 06:12
0

Sorry Guy for wasting your time I made one silly mistake.

db.execSQL("create table" + TABLE_NAME + "(ID INTEGER PRIMARY KEY AUTOINCREMENT)");

instead of this db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT)");

Space made application crash. thanks for all help.

Bhaumik
  • 11
  • 1
  • 7