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?
Aucun commentaire:
Enregistrer un commentaire