Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » database code& console( need some help in code + output of console)
database code& console [message #1050774] Sat, 27 April 2013 18:48
Dream Hal is currently offline Dream Hal
Messages: 2
Registered: April 2013
Junior Member
Hello everyone ;

I am working out on quiz application for android , I still beginner so I need your help in my database code


It doesn't work , what's wrong with it ?



package com.example.physicsquizapp;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

public class DataBase extends SQLiteOpenHelper{

	
	private static final String DATABASE_NAME = "questionBank.db";
	private static String DB_PATH = "/data/data/com.example.physicsquizapp/databases/";
	private static final int DATABASE_VERSION = 1;
    
    public static final String TABLE_NAME1 = "Questions";
    public static final String QUESTION_ID = BaseColumns._ID;
    public static final String QUESTION_BODY  = "Question_body";
    public static final String FIRST_CHOICE = "first_choice";
    public static final String SECOND_CHOICE = "second_choice";
    public static final String THIRD_CHOICE = "third_choice";
    public static final String CORRECT_ANSWER_NUMBER = "correct_answer_number";

    
   
    
    public static final String TABLE_NAME2 = "Type";
    public static final String TYPE_ID = BaseColumns._ID;
    public static final String TYPE_DESC = "type_desc";


    public static final String TABLE_NAME3 = "Quiz";
    public static final String QUIZ_ID = BaseColumns._ID;

    public static final String TABLE_NAME4 = "Level";
    public static final String LEVEL_ID = BaseColumns._ID;
    public static final String LEVEL_DESC = "level_desc";

    public static final String TABLE_NAME5 = " Chapter";
    public static final String CHAPTER_ID = BaseColumns._ID;
    public static final String CHAPTER_NAME = "ch_name";



  
    
    SQLiteDatabase db = getWritableDatabase();


    
    public DataBase(Context context) {
                    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    
    @Override
    public void onCreate(SQLiteDatabase db) {
                     String sql1 ="CREATE TABLE " + TABLE_NAME1 + " ("
                     + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                     + QUESTION_BODY+ " TEXT NOT NULL, "
                     + FIRST_CHOICE + " TEXT NOT NULL, "
                     + SECOND_CHOICE + " TEXT NOT NULL, "
                     + THIRD_CHOICE + " TEXT NOT NULL, "
                     + CORRECT_ANSWER_NUMBER + " INTEGER"
                     + ");";
                     
                     
    
                     String sql2 ="CREATE TABLE " +TABLE_NAME2+" ("
                             + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                             + TYPE_DESC +"TEXT NOT NULL"
                             +");";
                     String sql3 ="CREATE TABLE " +TABLE_NAME3+" ("
                             + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT "
                             
                             +");";
   
                     String sql4 ="CREATE TABLE " +TABLE_NAME4+" ("
                             + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                             + LEVEL_DESC +"TEXT NOT NULL"
                             +");";
                     
                     String sql5 ="CREATE TABLE " +TABLE_NAME5+" ("
                             + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
                             +  CHAPTER_NAME+"TEXT NOT NULL"
                             +");";
   
    
    
    
    
    
                     db.execSQL(sql1 );
                     db.execSQL(sql2);
                     db.execSQL(sql3);
                     db.execSQL(sql4);
                     db.execSQL(sql5);
    
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME1 +TABLE_NAME2+TABLE_NAME3+TABLE_NAME4+TABLE_NAME5);
                      onCreate(db);

    }
    
    public void insert(String q_body, String  first , String  second , String  third , int number) {
                      ContentValues values = new ContentValues();
                      values.put(QUESTION_BODY  , q_body);
                      values.put(FIRST_CHOICE, first);
                      values.put(SECOND_CHOICE, second);
                      values.put(THIRD_CHOICE, third);
                      values.put(CORRECT_ANSWER_NUMBER, number);

                      db.insertOrThrow(TABLE_NAME1, null, values);
    }

 public void insertType(String t_f , String m_choise){
	
	 ContentValues values = new ContentValues();
	 values.put(TYPE_DESC  , t_f);
	 values.put(TYPE_DESC  ,m_choise );

	 db.insertOrThrow(TABLE_NAME2, null, values);
	 
 }  
 public void insertLevel(String easy, String hard){
		
	 ContentValues values = new ContentValues();
	 values.put(LEVEL_DESC  , easy);
	 values.put(LEVEL_DESC  ,hard );

	 db.insertOrThrow(TABLE_NAME4, null, values);
	 
 } 
 public void insertChapter(String name){
		
	 ContentValues values = new ContentValues();
	 values.put(CHAPTER_NAME  , name);
	 

	 db.insertOrThrow(TABLE_NAME5, null, values);
	 
 } 
 
    
    public Cursor getAll(Activity activity) {
                      String[] from = { TYPE_ID, QUIZ_ID,QUESTION_BODY,LEVEL_ID, FIRST_CHOICE, TYPE_DESC, SECOND_CHOICE, THIRD_CHOICE, CORRECT_ANSWER_NUMBER};
                      String order = QUIZ_ID;
                      
                      Cursor cursor = db.query(TABLE_NAME1, from, null, null, null, null, order);
                      activity.startManagingCursor(cursor);
                      
                    return cursor;
    }

public void updateRow(long _id, String q_body, String  first , String  second , String  third , int number, String  t_f , String  m_choise ,String easy ,String    hard, String  name) {
ContentValues args = new ContentValues();
args.put(QUESTION_BODY  , q_body);
args.put(FIRST_CHOICE, first);
args.put(SECOND_CHOICE, second);
args.put(THIRD_CHOICE, third);
args.put(CORRECT_ANSWER_NUMBER, number);

args.put(TYPE_DESC, t_f);
args.put(TYPE_DESC, m_choise);
args.put(LEVEL_DESC, easy);
args.put(LEVEL_DESC, hard);
args.put(CHAPTER_NAME, name);

db.update(TABLE_NAME1 + TABLE_NAME2 + TABLE_NAME3 + TABLE_NAME4 + TABLE_NAME5 , args, " QUESTION_ID  +TYPE_ID  + QUIZ_ID +LEVEL_ID + CHAPTER_ID =?" , new String[] {""+ _id});
}
}




and this Console



[2013-04-27 17:31:16 - physics questionbank app] adb is running normally.
[2013-04-27 17:31:16 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 17:31:17 - physics questionbank app] Automatic Target Mode: launching new emulator with compatible AVD 'androidX'
[2013-04-27 17:31:17 - physics questionbank app] Launching a new emulator with Virtual Device 'androidX'
[2013-04-27 17:31:18 - Emulator] Failed to create Context 0x3005
[2013-04-27 17:31:18 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[color=red][2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:31:18 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 17:31:19 - physics questionbank app] New emulator found: emulator-5554
[2013-04-27 17:31:19 - physics questionbank app] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-27 17:31:20 - physics questionbank app] emulator-5554 disconnected! Cancelling 'com.example.physicsquizapp.BackGround activity launch'!
[2013-04-27 17:40:06 - physics questionbank app] ------------------------------
[2013-04-27 17:40:06 - physics questionbank app] Android Launch!
[2013-04-27 17:40:06 - physics questionbank app] adb is running normally.
[2013-04-27 17:40:06 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 17:40:06 - physics questionbank app] Automatic Target Mode: launching new emulator with compatible AVD 'androidX'
[2013-04-27 17:40:06 - physics questionbank app] Launching a new emulator with Virtual Device 'androidX'
[2013-04-27 17:40:06 - Emulator] Failed to create Context 0x3005
[color=red][2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 17:40:06 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[color=red][2013-04-27 17:40:06 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 17:40:07 - physics questionbank app] New emulator found: emulator-5554
[2013-04-27 17:40:07 - physics questionbank app] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-27 17:40:38 - physics questionbank app] HOME is up on device 'emulator-5554'
[2013-04-27 17:40:38 - physics questionbank app] Uploading physics questionbank app.apk onto device 'emulator-5554'
[2013-04-27 17:40:39 - physics questionbank app] Installing physics questionbank app.apk...
[2013-04-27 17:40:58 - physics questionbank app] Success!
[2013-04-27 17:40:59 - physics questionbank app] Starting activity com.example.physicsquizapp.BackGround on device emulator-5554
[2013-04-27 17:41:00 - physics questionbank app] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.physicsquizapp/.BackGround }
[2013-04-27 19:04:08 - physics questionbank app] ------------------------------
[2013-04-27 19:04:08 - physics questionbank app] Android Launch!
[2013-04-27 19:04:08 - physics questionbank app] adb is running normally.
[2013-04-27 19:04:08 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 19:04:09 - physics questionbank app] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'androidX'
[2013-04-27 19:04:09 - physics questionbank app] Uploading physics questionbank app.apk onto device 'emulator-5554'
[2013-04-27 19:04:11 - physics questionbank app] Installing physics questionbank app.apk...
[2013-04-27 19:04:31 - physics questionbank app] Success!
[2013-04-27 19:04:31 - physics questionbank app] Starting activity com.example.physicsquizapp.BackGround on device emulator-5554
[2013-04-27 19:12:04 - physics questionbank app] ------------------------------
[2013-04-27 19:12:04 - physics questionbank app] Android Launch!
[2013-04-27 19:12:04 - physics questionbank app] adb is running normally.
[2013-04-27 19:12:04 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 19:12:04 - physics questionbank app] Automatic Target Mode: launching new emulator with compatible AVD 'androidX'
[2013-04-27 19:12:04 - physics questionbank app] Launching a new emulator with Virtual Device 'androidX'
[2013-04-27 19:12:08 - Emulator] Failed to create Context 0x3005
[color=red][2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:08 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[color=red][2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:08 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:08 - physics questionbank app] ------------------------------
[2013-04-27 19:12:08 - physics questionbank app] Android Launch!
[2013-04-27 19:12:08 - physics questionbank app] adb is running normally.
[2013-04-27 19:12:08 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 19:12:08 - physics questionbank app] Automatic Target Mode: launching new emulator with compatible AVD 'androidX'
[2013-04-27 19:12:08 - physics questionbank app] Launching a new emulator with Virtual Device 'androidX'
[2013-04-27 19:12:09 - physics questionbank app] New emulator found: emulator-5554
[2013-04-27 19:12:09 - physics questionbank app] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-27 19:12:11 - Emulator] WARNING: Data partition already in use. Changes will not persist!
[2013-04-27 19:12:11 - Emulator] Failed to create Context 0x3005
[2013-04-27 19:12:11 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2013-04-27 19:12:11 - Emulator] WARNING: Cache partition already in use. Changes will not persist![color=red]
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:11 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:11 - Emulator] Failed to allocate memory: 1455
[2013-04-27 19:12:11 - Emulator] 
[2013-04-27 19:12:11 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2013-04-27 19:12:11 - Emulator] Please contact the application's support team for more information.
[2013-04-27 19:12:31 - physics questionbank app] emulator-5554 disconnected! Cancelling 'com.example.physicsquizapp.BackGround activity launch'!
[2013-04-27 19:12:36 - physics questionbank app] ------------------------------
[2013-04-27 19:12:36 - physics questionbank app] Android Launch!
[2013-04-27 19:12:36 - physics questionbank app] adb is running normally.
[2013-04-27 19:12:36 - physics questionbank app] Performing com.example.physicsquizapp.BackGround activity launch
[2013-04-27 19:12:36 - physics questionbank app] Automatic Target Mode: launching new emulator with compatible AVD 'androidX'
[2013-04-27 19:12:36 - physics questionbank app] Launching a new emulator with Virtual Device 'androidX'
[color=red][2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:37 - Emulator] Failed to create Context 0x3005
[color=red][2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:37 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[color=red][2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB
[2013-04-27 19:12:37 - Emulator] could not get wglGetExtensionsStringARB[/color]
[2013-04-27 19:12:38 - physics questionbank app] New emulator found: emulator-5554
[2013-04-27 19:12:38 - physics questionbank app] Waiting for HOME ('android.process.acore') to be launched...
[2013-04-27 19:13:29 - physics questionbank app] HOME is up on device 'emulator-5554'
[2013-04-27 19:13:29 - physics questionbank app] Uploading physics questionbank app.apk onto device 'emulator-5554'
[2013-04-27 19:13:30 - physics questionbank app] Installing physics questionbank app.apk...
[2013-04-27 19:14:21 - physics questionbank app] Success!
[2013-04-27 19:14:21 - physics questionbank app] Starting activity com.example.physicsquizapp.BackGround on device emulator-5554
[2013-04-27 19:14:24 - physics questionbank app] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.physicsquizapp/.BackGround }


Previous Topic:Eclipse Juno and Ant 1.9 Trouble
Next Topic:Null analysis - unexpected warnings on final field
Goto Forum:
  


Current Time: Thu Oct 30 16:17:27 GMT 2014

Powered by FUDForum. Page generated in 0.01823 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software