hi,
    I have implement this example. but i got an error.

    I have write the code just for create database, create table,
insert values in it.

    When I run application it displays nothing.

    But when i tried to open my database from command prompt Like:

    ls data/data/MyPackageNm

    Then it gives only a Lib folder rather than database and Lib both.

    So, i tried to found error via Log cat and put my code in try and
catch.

    I got an error while creating table.

    its gave Null Pointer exception.

    Please any one help me.

    My Log cat is like that and i have use this sample example as my
code.

    Thanks.

Log Cat:-

uid=10032 gids={}
09-29 15:36:09.727: DEBUG/dalvikvm(813): LinearAlloc 0x0 used 538516
of 4194304 (12%)
09-29 15:36:09.837: INFO/jdwp(822): received file descriptor 10 from
ADB
09-29 15:36:10.128: INFO/Niketa(822): database created
09-29 15:36:10.137: INFO/Niketa(822): database opened
09-29 15:36:10.137: INFO/Niketa(822): ------null
09-29 15:36:10.147: INFO/Niketa(822): +++++
+java.lang.NullPointerException
09-29 15:36:10.337: INFO/ActivityManager(52): Displayed activity
com.db/.DataBaseWork: 754 ms
09-29 15:36:15.507: DEBUG/dalvikvm(675): GC freed 44 objects / 1800
bytes in 151ms
09-29 15:36:15.507: DEBUG/dalvikvm(118): GC freed 3 objects / 72 bytes
in 143ms
09-29 15:36:15.527: DEBUG/dalvikvm(92): GC freed 1539 objects / 70560
bytes in


-----------------------------------------------------------------------------------------------------------------------------------------


My java code is:

package com.db;

//import java.io.FileNotFoundException;
import java.util.ArrayList;

import android.app.Activity;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;

public class DataBaseWork extends Activity {
        private final String MY_DATABASE_NAME = "LoginDB";
    private final String MY_DATABASE_TABLE = "Login1";
    private final String tag="Niketa";


    @Override
    public void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         ArrayList<String> results = new ArrayList<String>();
         SQLiteDatabase myDB = null;
         try {

              /* Create the Database (no Errors if it already exists)
*/
              this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE,
null);
              Log.i(tag,"database created");

              /* Open the DB and remember it */

              myDB = this.openDatabase(MY_DATABASE_NAME, null);
              Log.i(tag,"database opened ");

              /* Create a Table in the Database. */
              try
              {
              myDB.execSQL("CREATE TABLE IF NOT EXISTS "
                                  + "LoginDB.Login1"
                                  + " (UserNm TEXT, PassWd TEXT)"
                                  +";");
              Log.i(tag,"table created ");
              }
          /*    catch(SQLException e1)
              {
                  Log.i(tag,"SQL EXception"+e1);
              }*/


              catch(Exception e)
              {
                  Log.i(tag,"------"+e.getMessage());
                  Log.i(tag,"++++++"+e);
              }

            /*  catch(SQLiteException se)
              {
                  Log.i(tag,"SQLite Error--------"+se);
              }*/
              /* Add two DataSets to the Table. */
              myDB.execSQL("INSERT INTO "
                                  + MY_DATABASE_TABLE
                                  + " (UserNm, PassWd)"
                                  + " VALUES ('abc', 'def');");
              Log.i(tag,"value inserted ");


              /* Query for some results with Selection and Projection.
*/
              Cursor c = myDB.rawQuery("SELECT UserNm,PassWd" +
                                       " FROM " + MY_DATABASE_TABLE
                                       + ";",
                                       null);
              Log.i(tag,"value seleted ");

              /* Get the indices of the Columns we will need */
              int firstNameColumn = c.getColumnIndex("UserNm");
              int ageColumn = c.getColumnIndex("PassWd");

              /* Check if our result was valid. */
              if (c != null) {
                   /* Check if at least one Result was returned. */
                  if (c.isFirst()) {
                        int i = 0;

                        do {
                             i++;

                             String firstName =
c.getString(firstNameColumn);
                             int age = c.getInt(ageColumn);
                             String ageColumName =
c.getColumnName(ageColumn);

                             results.add("" + i + ": " + firstName
                                            + " (" + ageColumName + ":
" + age + ")");
                        } while (c!=null);
                   }
              }
         }
         catch (Exception e)
         {
                 Log.i(tag,"Error----->"+e);
         }
         finally
         {
              if (myDB != null)
                   myDB.close();
         }
         this.setListAdapter(new ArrayAdapter<String>(this,
                 android.R.layout.simple_list_item_1, results));
  }


        private void setListAdapter(ArrayAdapter<String> arrayAdapter)
        {
        }

        private SQLiteDatabase openDatabase(String my_database_name2, Object
object)
        {
                return null;
        }

        private void createDatabase(String my_database_name2, int i,
                        int modePrivate, Object object)
        {


        }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to