Android Studio SQLite Database Example

Tan Woon How

He is a learner and know little around .Net and Java. He learned and share if you see his mistake... feel free to comment and laugh at him... and also please help to correct him.

You may also like...

  • Stefan Pisicasi

    Hi Tan,

    I have a problem with PlaceholderFragment.

    Error:

    Unresolved class ‘PlaceholderFragment’

    How can to solve it?

  • Nilmar Castro

    Hi Tan,

    Can you explain on how to get the number of registers in DB?
    As I could see you have an iCount inside the getConfigByInt function. But I need to know this before any action.

  • Modito Musa

    Hey Tan Nice Tutorial I just wanted to know how to view only one student by his id lets say i pass his Id and his result pops out on a new activity from what you did it displays the list of all the student.

  • Jacques IBISUL

    Hello, how i do export and import data from sd? You have an example? I doesnt have ideia how to call the methods in class that created my database.

  • Cherif Bouanani

    Hello
    Thank you very much for the efforts you are making.
    Then I will create an android application to recover SMS and retrieve their data and store it in a SQLite database. I created the application that allows the reception of messages but I can not create the SQLite database.
    You can help me, thanks in advance

    • Tan Woon How

      Just download this tutorial project and you will able to learn how it create the database and do simple CRUD.

      • Cherif Bouanani

        Can you give me your e-mail address please

      • Cherif Bouanani

        Hello
        I created my SQLite database, now I want to export it in CSV format, what I have to do, is what I have to create a class, or there is a function that allows me to export My database or there is another method to do
        thank you in advance

  • Cherif Bouanani

    Hello
    Thank you very much for the efforts you are making.
    Then I will create an android application to recover SMS and retrieve their data and store it in a SQLite database. I created the application that allows the reception of messages but I can not create the SQLite database.
    You can help me, thanks in advance

  • Paul Tilson

    I am new to Android Studio and have built about 4 examples that involve SQLite databases. After importing the sample projects and running them, all I get is “Hello World”. I can look at the code and it includes the code to create and update and etc. but it is not getting executed. It never starts. What is causing this.

  • frans ringo

    Hey Tan, i’ve tried your source in here. But i can’t see where do you put the content where i must put the if my list view (same like yours, @+id/list). I’ll be very gratefull if u can help me bro. thanks a lot.

    • Tan Woon How

      I not sure i get what you mean. You need to put it in XML. something like in activity_main.xml.

      • frans ringo

        I’m sorry for my bad english. I mean u didn’t call the method for that listView on your class.

        • Tan Woon How

          We do call to bind data, look at this line in MainActivity.java

          ListAdapter adapter = new SimpleAdapter( MainActivity.this,studentList, R.layout.view_student_entry, new String[] { “id”,”name”}, new int[] {R.id.student_Id, R.id.student_name});
          setListAdapter(adapter);

          This do the trick. Hope i answered you. 🙂

          • frans ringo

            Wow, i miss that li’l man over there. Thanks man!

  • Maung Aye

    I am having following errors when I click the add button, Your help is much appreciated

    03-10 15:45:53.225 3485-3500/? E/EGL_emulation: tid 3500: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)

    03-10 15:45:54.686 3485-3500/com.example.maungmaungaye.sqlitedb E/EGL_emulation: tid 3500: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)

    03-10 15:46:21.880 3485-3485/com.example.maungmaungaye.sqlitedb E/AndroidRuntime: FATAL EXCEPTION: main

    Process: com.example.maungmaungaye.sqlitedb, PID: 3485

    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.maungmaungaye.sqlitedb/com.example.maungmaungaye.sqlitedb.StudentDetail}; have you declared this activity in your AndroidManifest.xml?

    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)

    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)

    at android.app.Activity.startActivityForResult(Activity.java:4225)

    at android.app.Activity.startActivityForResult(Activity.java:4183)

    at android.app.Activity.startActivity(Activity.java:4522)

    at android.app.Activity.startActivity(Activity.java:4490)

    at com.example.maungmaungaye.sqlitedb.MainActivity.onClick(MainActivity.java:37)

    at android.view.View.performClick(View.java:5637)

    at android.view.View$PerformClick.run(View.java:22429)

    at android.os.Handler.handleCallback(Handler.java:751)

    at android.os.Handler.dispatchMessage(Handler.java:95)

    at android.os.Looper.loop(Looper.java:154)

    at android.app.ActivityThread.main(ActivityThread.java:6119)

    at java.lang.reflect.Method.invoke(Native Method)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

    • Maung Aye

      Thanks

      • Tan Woon How

        Sorry for late reply, this error is because of you not declare you activity in your AndroidManifest.xml? Meaning add the “StudentDetail” as an activity to the android manisfest this way : ..

        You don’t have to do this if you add as activity unless you create your interface(xml) and code separately then you need to add the line manually into manifest.

  • Vasudeo Rateria

    i have a question that if we could add images to a sqlite database?
    i am working on a project which has a structure simillar to amazon.com like when you click on an image it gives you more related images and some info . please help.
    thank you in advance

  • Vasudeo Rateria

    hi.
    i tried the code. it is very good. the problem is that when i click the add button the app immediately stops but when i click the list all button it shows no student!.
    what can i do?

    • Tan Woon How

      Show me the error. Try to have a look on logcat panel

  • vers191rm

    Hello Tan, great tutorial. Tried it out and it works. I want to use it for my other project where i’m working with fragments. My question the code in MainActivity, I want to put it in my fragment class so when I click my button it’ll open the view where you can add or list all but I don’t know how as it keeps giving me error..

    Any help would be great from you! 🙂

    • vers191rm

      Here’s my fragment class. doesn’t do anything but open the view when I click the button from my MainActivity class

      public class testFragment extends Fragment
      {
      public testFragment()
      {

      }

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

      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
      {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.testFragment_test, container, false);
      }
      }

      here’s from my onCreate method in MainActivity

      case R.id.test:
      Toast.makeText(getApplicationContext(),”test showed”,Toast.LENGTH_SHORT).show();
      testFragment testFragment = new testFragment ();
      android.support.v4.app.FragmentTransaction fragmentTransaction1 = getSupportFragmentManager().beginTransaction();
      fragmentTransaction1.replace(R.id.fragmentF, testFragment );
      fragmentTransaction1.commit();
      return true;

      • Tan Woon How

        Hi,
        Quick glance, i don’t spot any issue, what error are you getting?

        • vers191rm

          Hello Tan, I didn’t clarify properly sorry. The only thing i’m missing is the code from the MainActivity. Do I also put it in my MainActivity class or somewhere else since i’m working with fragments?

          • Tan Woon How

            Ya. post here, so i could have a look. and tell me what errors are you getting.

          • vers191rm

            It says Cannot resolve method ‘getListView()’ and Cannot resolve method ‘setListAdapter(android.widget.ListAdapter)’

            I assume it’s beacuse i’m not extending ListActivity in MainActivity? i’m already extending AppCompatActivity for my navigationview and it’s fragments and I can’t extend more than 1 class.. Any help please?

            – Cheers

          • Tan Woon How

            Ah ok.
            Try have a look on this tutorial on how the listview work in activity without extending the ListView . http://instinctcoder.com/android-studio-sqlite-search-searchview-actionbar/

            Look at the MainActivity.java

          • vers191rm

            I got past that problem and it works.but it can’t resolve the id “list” from my ListView.. Here’s the code in my MainActivity.

            @Override
            public void onClick(View view) {
            if (view== findViewById(R.id.btnAdd)){

            Intent intent = new Intent(this,StudentDetail.class);
            intent.putExtra(“student_Id”,0);
            startActivity(intent);

            }else {

            StudentRepo repo = new StudentRepo(this);

            ArrayList<HashMap> studentList = repo.getStudentList();
            if(studentList.size()!=0) {
            listView = (ListView) findViewById(R.id.list);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
            @Override
            public void onItemClick(AdapterView parent, View view,int position, long id) {
            student_Id = (TextView) view.findViewById(R.id.student_Id);
            String studentId = student_Id.getText().toString();
            Intent objIndent = new Intent(getApplicationContext(),StudentDetail.class);
            objIndent.putExtra(“student_Id”, Integer.parseInt( studentId));
            startActivity(objIndent);
            }
            });
            ListAdapter adapter = new SimpleAdapter( MainActivity.this,studentList, R.layout.view_student_entry, new String[] { “id”,”name”}, new int[] {R.id.student_Id, R.id.student_name});
            listView.setAdapter(adapter);
            }else{
            Toast.makeText(this,”No student!”,Toast.LENGTH_SHORT).show();
            }

            }
            }

          • vers191rm

            Another problem. Since I want to open the activity from one of my fragments before I go to create a student I get problems to add the buttons in my fragment class. I don’t know what i’m doing wrong. It gives me a “java.lang.NullPointerException: Attempt to invoke virtual method ‘android.view.View android.widget.Button.findViewById(int)’ on a null object reference”

            Here’s my fragment class.

            public class ClothFragment extends Fragment implements View.OnClickListener
            {
            public ClothFragment()
            {

            }

            Button btnAdd,btnGetAll;

            public void onClick(View view)
            {
            }

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

            btnAdd = (Button) btnAdd.findViewById(R.id.btnAdd);
            btnAdd.setOnClickListener(this);

            btnGetAll = (Button) btnGetAll.findViewById(R.id.btnGetAll);
            btnGetAll.setOnClickListener(this);
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
            // Inflate the layout for this fragment
            return inflater.inflate(R.layout.cloth_clothes, container, false);
            }
            }

          • vers191rm

            I hope i’m close to solve it. If it helps I can send you my project if it’s easier to look at the error from there?

            – Cheers

          • Tan Woon How

            Hmmm.. try harder… What good about programming is when you solved a headache issue not get the work done. Try again. You’re close.

          • Tan Woon How

            You need to make sure your list is exists on the layout you try to inflate.

  • savitririshma

    Hi Tan.. Thankyou for great tutorial. I followed urs and want to improve little on here. I make the list student in recyclerview, when one of them clicked, it is go to DetailsStudent.java. And in there will show Edit button on Toolbar. Can u lead me how to implementing i.putExtras in Icon menu toolbars, pls? Im stuck here, idk how to return back my data in edittext. Thanks.

    • Tan Woon How

      Hi
      What do you mean by return data back in edittext? I have a tutorial on searching data and do have a button on toolbar. Not sure is that going to help you.

      Let me know

  • Rudeboy Kwasi-Mensah

    Hello, Tan, please how can I get a copy of mysql online dbase, and sync it with my android app. So the user can make CRUD on the phone and gets synced with the server dB when he gets internet connection. Also I want any changes on the server to sync with the phone as well. Thanks

    • Tan Woon How

      Hey RudeBoy,

      You are rude 🙂
      Sorry i don’t have mysql server version, however the concept still the same. Mean you connect to the server and grab the data, you could refer to here if you use .Net as tool, please refer to this tutorial http://instinctcoder.com/how-to-call-asp-net-web-api-from-android-studio/. but if you don’t is still fine because you Android code work the same.

      This tutorial give you the idea how to connect to the server, and retrieve data, so when you get the data and save it into your device’s database.

      • Rudeboy Kwasi-Mensah

        Lol, I am not rude, Tan. Thank you very much for ur help. You are such a genius. <3 One last question is how do I implement a search by taking two inputs from a user. Thus for example, date inputs between dateA and dateB. So the result will display records between the two dates. Hope I make sense. Thank you once again. You make me love programming.

        • Tan Woon How

          Oh really, I don’t know i could influence other. Haha this make me laugh.

          You could have a look on this but you have create interface to accept 2 parameters, the example show you the search function but only accept single input instinctcoder.com/android-studio-sqlite-search-searchview-actionbar/

          Or you could come out something more straight forward, base on the example link. meaning you create a simple activity to put in date control and single button and the search function could follow as in the example.

          hopes that help.

          • Rudeboy Kwasi-Mensah

            Oh yess, u are a great influence. You are excellent tutor. I wish u were my friend I can hang out everyday with. Thank you very much. <3

  • Kumari

    Thank you so much. This tutorial is so helpful! I just wanted to add a small step to your good work which is to add the “StudentDetail” as an activity to the android manisfest this way :
    Have a nice day 🙂

    • Tan Woon How

      Hi kumari,
      You dont have tobdo this if you add as activity unless you create your interface(xml) and code separately then you need to add the line manually into manifest.

      • Kumari

        Yes that was the case in the project I am working on. Thanks again 🙂

  • TORNADO DESIGN

    Great work I wish you success
    I am work on SQlite in seam idea, but I want the user that does not modify anything, Only search. and I am change data from the database when i publish update
    plz i want the code for search button
    good luck and thnx

  • Zulkifli

    hii.. nice tutorial, very help full for me newby studying android.
    anyway..im trying to creata radio group with two option radio button “yes” and “no”, i want to save the selected radio button into SQLite DB, how can i do that ??
    i was try and got error..
    do you have tutorial ?
    thank you brother.. 🙂

  • Zachary De Nardi

    This is an awesome tutorial! I’ve been self teaching for about 3 weeks and this was a really good project. I kinda made it my own and made some modification (Added a new column and changed some things around)

    I ran into a snag that I can’t seem to fix…I can’t see any “Text” on the ‘Main’ activity at start up. I can see a raised button where text should be, but it doesnt show (using this example) the Students Name. Can you lend a hand?

    • Tan Woon How

      Hi,
      I’m just guessing. Cause you doesn’t mentioned detail on your issue.
      1. You might not increase db version number?? –> Check the DBHelper.java at line 11.
      2. Did you add new ‘Text’ control into view_student_entry.xml?
      3. Did you bind the new column in the MainActivity.java at line 56?

      Cheers. I just random just give you some answer so that you won’t have to wait me online.

      • Zachary De Nardi

        Thanks for the quick response!

        I got it last night…it was the binding the new column with the new column name.

        Thanks so much! Great tutorial. Really helped me learn how to create some nice app groundwork.

  • Raymon Cooley

    as far as I can tell I did everything exaclty how you have it but when I click on the “add” button the program crashes and I get this error:

    E/SQLiteLog: (1) near “TABLEStudent”: syntax error
    E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.electrohaven.i_hate_ms.databasetest, PID: 7324
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.electrohaven.i_hate_ms.databasetest/com.electrohaven.i_hate_ms.databasetest.StudentDetail}: android.database.sqlite.SQLiteException: near “TABLEStudent”: syntax error (code 1): , while compiling: CREATE TABLEStudent(idINTEGER PRIMARY KEY AUTOINCREMENT,nameTEXT,ageINTEGER,emailTEXT)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2505)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2565)
    at android.app.ActivityThread.access$900(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1395)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5821)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
    Caused by: android.database.sqlite.SQLiteException: near “TABLEStudent”: syntax error (code 1): , while compiling: CREATE TABLEStudent(idINTEGER PRIMARY KEY AUTOINCREMENT,nameTEXT,ageINTEGER,emailTEXT)
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:891)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:502)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
    at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1775)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1706)
    at com.electrohaven.i_hate_ms.databasetest.DBHelper.onCreate(DBHelper.java:25)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
    at com.electrohaven.i_hate_ms.databasetest.StudentRepo.getStudentById(StudentRepo.java:83)
    at com.electrohaven.i_hate_ms.databasetest.StudentDetail.onCreate(StudentDetail.java:53)
    at android.app.Activity.performCreate(Activity.java:6262)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2458)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2565)
    at android.app.ActivityThread.access$900(ActivityThread.java:150)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1395)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:168)
    at android.app.ActivityThread.main(ActivityThread.java:5821)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
    D/Process: killProcess, pid=7324
    D/Process: com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:113 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690

    I am probably just missing somethng, i also added StudentDetail.java in the manafest.

    • Tan Woon How

      Hi
      Check your query on creating table.
      Need space on “table student”. And “id INTEGER”.
      CREATE TABLEStudent(idINTEGER PRIMARY KEY

      • Raymon Cooley

        Thank you, was indeed a typo in the StudentRepo, all is good now. (side note, I have done blogs and such many times and its nice to finally get a quick response, you did a great job with the tutorial and helping others.)

  • Lourenço Lazzare

    Not delete if exist one register…. Delete te name, email, age, not delete the rows. Solution?

    • Tan Woon How

      Hi,
      Instead of delete use update statement. Refer to StudentRepo.jave update function. use that function to update instead of Delete.

  • Mario German Agudelo

    An excellent tutorial, thanks for sharing your knowledge with all of us, I have the following question: I have a database already created and which is shown in a Recyclerview with values such as ID, name and telephone number and I want to place a spinner which leave me place a set of values, as I can do so that when you click on a value of the spinner that value in SQLite is saved and then when reentering activity show me the stored value, I appreciate all the help you can me offer. Thank you.

    • Tan Woon How

      Hi Mario,
      So what is your problem? Do you have problem for planning spinner? Refer here if you need help, http://instinctcoder.com/android-studio-spinner-populate-data-sqlite/. Or you need to save the value when spinner change? I assume you manage to place your spinner into the recycleview. and you need to place you code in your adapter when the spinner value change and save the value into the database. Something like this

      spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) {
      // your code here
      }

      @Override
      public void onNothingSelected(AdapterView parentView) {
      // your code here
      }

      });

  • Sandro

    Hello , can you please show me the code when I only needed a limited number of students. For example I only need to store 5 students and it should not be greater than 5

    • Tan Woon How

      Hmmm…Any reason why you control number of records save into database? Is kind of weird to me.

      You can achieve by counting record in the table first if not exceed 5 records then proceed to insert. Samepl code as below.

      public void insert2(Student student) {

      //Open connection to write data
      SQLiteDatabase db = dbHelper.getWritableDatabase();
      Integer noStudent=0;

      String selectQuery = “SELECT COUNT(*) as NoStudent ” +
      ” FROM ” + Student.TABLE;

      Cursor cursor = db.rawQuery(selectQuery, null);
      if (cursor.moveToFirst()) {
      noStudent = cursor.getInt(cursor.getColumnIndex(“NoStudent”));
      }
      cursor.close();

      if (noStudent<5){
      ContentValues values = new ContentValues();
      values.put(Student.KEY_age, student.age);
      values.put(Student.KEY_email,student.email);
      values.put(Student.KEY_name, student.name);

      // Inserting Row
      long student_Id = db.insert(Student.TABLE, null, values);

      }

      db.close(); // Closing database connection
      }

      • Sandro

        ba kayo matututong magbasa ng chat? Nakakapagod kayo pramis ? #thesischatbox
        ..

        Chat Conversation Start

        10:39am

        Nasa raon ako.. Wala e gizmo

        Trish

        Awtsu. Patext si alain na tuloy tayo
        Txt nyo din si daniel… Nandun na daw sya

        Trish

        sandro asa raon ka pa?

        bili ka stranded wire
        Ew wala na

        Trish

        Bading.

        1:41pm

        file:///C:/Users/marksandrotutor/Desktop/My%20Files/Pag-aaral%20Folder/THESIS/Android%20Studio/Allowing%20Other%20Apps%20to%20Start%20Your%20Activity%20_%20Android%20Developers.html
        https://developer.android.com/training/sharing/send.html
        Sending Simple Data to Other Apps | Android Developers
        When you construct an intent, you must specify the action you want the intent to “trigger.” Android defines several actions, including ACTION_SEND which, as you can probably guess, indicates that the intent is sending data from one activity …
        developer.android.com
        .
        8:08pm

        if (noStudent<5){
        ContentValues values = new ContentValues();
        values.put(Student.KEY_age, student.age);
        values.put(Student.KEY_email,student.email);
        values.put(Student.KEY_name, student.name);
        // Inserting Row
        long student_Id = db.insert(Student.TABLE, null, values);

        }
        im getting missing return statement do you think that command.. is it missing else {}

      • Sandro

        if (noStudent<5){
        ContentValues values = new ContentValues();
        values.put(Student.KEY_age, student.age);
        values.put(Student.KEY_email,student.email);
        values.put(Student.KEY_name, student.name);

        // Inserting Row
        long student_Id = db.insert(Student.TABLE, null, values);

        }

        that command.. is it missing else {}

        im getting missing return statement

        • Tan Woon How

          You need to change your return from int to void if you got nothing to return from your function. For example public void insert (){
          //nothing return
          }

          • Sandro

            I’m having an error at student repo saying

            Incompatible types:

            Required : int

            Found: Void

            at this line

            _Police_Id = repo.insert(police);
            When I changed int to void

          • Sandro

            Change all police to student.. Sorry 😀

  • Unveiled Tech

    hello , how to pass the listview item value to next activity

    -thanks

    • Tan Woon How

      Look at these block of code in MainActivity.java, between line 47 to 53, the passing value to next activity is this line objIndent.putExtra(“student_Id”, Integer.parseInt( studentId));

  • iulia

    Hello i tried your tutorial on Android Studio. But when i install the app and open it, it crushes. Sorry can you help me… i’m doing it on an device maybe is something wrong on it… thank you

    • Tan Woon How

      Could you see any errors from the logcat panel? Paste it here.

      • iulia

        When i do debug on the device i have:
        06-21 14:01:36.170 766-766/it.weebiiz.sqlitedb I/System.out: Sending WAIT chunk
        06-21 14:01:36.510 766-772/it.weebiiz.sqlitedb I/dalvikvm: Debugger is active
        06-21 14:01:36.570 766-766/it.weebiiz.sqlitedb I/System.out: Debugger has connected
        06-21 14:01:36.570 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:36.770 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:36.970 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:37.170 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:37.370 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:37.570 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:37.770 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:37.970 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:38.170 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:38.370 766-766/it.weebiiz.sqlitedb I/System.out: waiting for debugger to settle…
        06-21 14:01:38.570 766-766/it.weebiiz.sqlitedb I/System.out: debugger has settled (1483)
        06-21 14:01:38.740 766-766/it.weebiiz.sqlitedb W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41665c80)
        06-21 14:01:42.030 766-766/it.weebiiz.sqlitedb I/Process: Sending signal. PID: 766 SIG: 9

        when i run the app on the device i have:
        06-21 14:03:32.060 8718-8718/it.weebiiz.sqlitedb W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41665c80)

        • Tan Woon How

          Please filter by on selected apps.

          • iulia

            it’s already selected app.

          • Tan Woon How

            Arhh…I got to say sorry first. I thought you have issue with your compiled APK. Then, I tried my self with this project in AS 2.1.2. I got the same error messages like you showed me. After applied the recommend steps i still find have the problem. (15 mins) …(Give up)

            Then, i just create another new project and (done in 5 mins) copy code from this page again. It’s done. :). I will update again. Thanks for reporting.

      • iulia

        and when i try to open your project that i downloaded from the link below it says: “The path ‘C./program files (x86)/Android/android-studio/sdk’ does not belong to a directory. Androi Studio will use this Android SDK instead ‘/Users/macbookpro/Library/android/sdk’ and will modify the project’s local.properties file. I click OK because i’m using a mac. After building Grandle i get
        Error:The project is using an unsupported version of the Android Gradle plug-in (0.7.3). The recommended version is 2.1.2.

        Starting with version 0.9.0 incompatible changes were introduced in the build language.
        Please read the migration guide to learn how to update your project.
        Open migration guide, fix plugin version and sync project
        i click Open migration guide and fix it…
        but then i have
        Error:(27, 0) Gradle DSL method not found: ‘runProguard()’
        Possible causes:The project ‘SQLiteDatabase’ may be using a version of Gradle that does not contain the method.
        Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
        Apply Gradle plugin

        i found that runproguard was renamed to minifyEnabled so i replace it.
        Then i sync again grandle and have this:
        Error:The SDK Build Tools revision (19.0.0) is too low for project ‘:sqlitedb’. Minimum required is 19.1.0
        so i change in grandle

        android {
        compileSdkVersion 19
        buildToolsVersion “19.1.0” com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Users/macbookpro/Library/Android/sdk/build-tools/19.1.0/aapt” finished with non-zero exit value 1
        but i can run the app.
        So i try to run it and get again:
        Error:Execution failed for task ‘:sqlitedb:processDebugResources’.
        > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘/Users/macbookpro/Library/Android/sdk/build-tools/19.1.0/aapt” finished with non-zero exit value 1

        What am i doing wrong?

        • Tan Woon How

          sorry migration I’m not sure. Because I’m not mac usr 🙂 may be you need copy file by file into mac android

  • Anggi Tiovany Siregar

    hello, i’m very beginner of android , thank a lot for the tutorial, I have tried this code but when i click list of student, i think the detail of the student will appear but doesn’t appear anything, what’s going on with it? what something that i need to add or change? thank you a lot

    • Tan Woon How

      Hi,
      Try to debug and see whether any id assigned into each student record, you set break point on line 50 of MainActivity.java, see any value for this variable ,studentId , other than 0.

      • Anggi Tiovany Siregar

        i have been debugging it, it said id = 0, and i tried to change student_id = 1, but the result same as before, so what i need to change, thanks a lot buddy.

        • Tan Woon How

          Hmmm… If you run the code directly from the download link, you should be able to see the same result as we do. Could you make sure the id column is auto increament, check this link on how you could check your database http://instinctcoder.com/how-to-browse-android-studio-emulator-sqlite-database/.

          Don’t worry it’s quite straight forward. 🙂

          and I’ll be here for you :).

          and make sure in your DBHelper.java the Id, column is autoincrement in line 25
          –> Student.KEY_ID + ” INTEGER PRIMARY KEY AUTOINCREMENT ,”

          • Anggi Tiovany Siregar

            I have checked DBHelper.java, and it’s same like above, is that caused i make target minSDKversion 7 and targetSDKversion 22 ?? or maybe cause i use android studio version 2.1.1? and i have tried the link that you gave to me, and i found crud.db and the content but when i click the list of student, the detail still doesn’t appear, sorry for questioning you too much. 😀

          • Tan Woon How

            Nothing to do with the version. Did you browse your data from the tools? Did you see column value and also the type of the column?

          • Anggi Tiovany Siregar

            here it is, there are 2 data that i have added in that crud.db, but i can’t see the detail when it runs, i’ve download your code, but when i compile it in android studio, it takes too long to compile it, so i make my own project but based on your code. or i’d better if i send my project to you?

          • Tan Woon How

            Try to click on the browse data tab and did you manage to see running number for column id?

          • Anggi Tiovany Siregar

            that’s the content

          • Tan Woon How

            You see there is a browse data beside the database structure’s tab if there value for column id then problem is in the code.

          • Anggi Tiovany Siregar

            hello, i have fixed the trouble yesterday, but there is one thing, when i add one data , the listview data doesn’t automatically refresh data in screen, i need to close after that open the app , and then new data appears, why it can be like that, how if i want the data automatically add into screen listview? thank you.

          • Tan Woon How

            Hi
            That’s great. Mind to tell readers what you did. So that they know what to do if have the same issue.

            Thus tutorial i try to keep thing simple. So i not include many things. To automatically reload the data. You could use onResume(). You could refer to this example for the sample code. http://instinctcoder.com/andro

          • Anggi Tiovany Siregar

            there are several difference among code that you post and code that we can download, i’d better readers follow code this page than download. there is one question, in student.java, how if i want to insert value date. it said can’t resolve date. so how to solve it ? thank you.

          • Tan Woon How

            Really? You mean the updated code with version 2.1.2 or the old version code? i recently update with new version and i think i just copied whatever appear in this page, should be the same. For old one, i not really recall as 2 years back 🙂

            For the date, as far as i know, there is no date column, refer to this https://www.sqlite.org/datatype3.html#section_2_2. So what you can do is format the date into whatever format you like and save it into text column.

          • Anggi Tiovany Siregar

            Hi buddy, Do you know maximum size of SQLite Database in android? thanks.

          • Tan Woon How

            as far as i know, there is no size limitation as long as you device have enough space.

            Some other information, you may find it relevant https://www.sqlite.org/limits.html

          • Tan Woon How

            Sorry when i checked from my phone i can’t see this picture, that’s means data inserted correctly into database. Then is something wrong with the code during its retrieve the data. Please check code in StudentRepo.java for this function.. getStudentList(), try debug line by debug and see what is the value been assigned into id column.

            Cheers.

  • 13456Fatimah Mohmmad

    hello thanks for the great tutorial, i have query about why you initialize the student id as 0 and never increment it ?

    • Tan Woon How

      Hi
      Id is primary key and also auto increment. So it should auto increase if your table doesn’t increase means you did not create column as autoincrement. Refer to DBhelper.java for example.

  • David

    What is that method you’re calling in MainActivity.java line 45 “ListView lv = getListView();” i can’t see where you declared it

    • Tan Woon How

      We’re extend the ListActivity in the class refer to line 26

      • David

        oh i see. thank you.

        Thanks for the quick response, Very nice post really helpful… it’s helped me do 70% of my work…

        I have a problem though. my MainActivity doesn’t exeted ListViewActivity, it is AppCompatActivity.
        when i populate my list view i do ListView lv = (ListView) findViewbyId(…)
        it works, but is gives me a problem when i click on item, only the top visible view id is on the listview no matter which item i click….

        • Tan Woon How

          hmmm..I’m not sure about your problem…

          If you don’t mind to have a look on this example, which is not extend ListActivity, maybe could help you move further? http://instinctcoder.com/android-studio-sqlite-search-searchview-actionbar/,
          That tutorial is almost identifical with this but just cover different widget.

          Have a look. Cheers!!!

        • Tan Woon How

          May be you make the id visible and see whether is the same id display for all records?

          Meaning remove this line android:visibility=”gone” from the view_Student_entry.xml.
          If you getting the same ID for all records, it could be you sql query having issue.

  • Rutuja Shah

    When i click on add it app closes

    • Rutuja Shah

      It’s solved

  • ricko monty

    Your code is awesome and I am very grateful to have it mate, but any chance maybe you could add a Searchview ? The thing is I could add many students and a search would be very helpful.

  • michael

    can you please email me I have a few questions [email protected]

    • Tan Woon How

      try ask here, so that your question could be benefit others.

  • Pingback: David’s MP3 Plan | Special Topics in Computer Science()

  • Pingback: David’s MP2 Progress Report | Special Topics in Computer Science()

  • Seemanta Bhowmick

    Can you please help me out by sending any working code of using Multiple tables in a SQLite Database in Android Studio?
    My email id: seemanta.bhowmick1992 at gmail dot com
    Thanks in advance.

    • Tan Woon How

      Err. i don’t have 1. If you could wait for another day,i make simple one, OK? and i’ve been dragging this sample for very longX100 time. Sorry for those who’re requested.

      • Seemanta Bhowmick

        Yeah sure I can wait for a day or two. I would be really greatful if you can make a simple one. Thank you.

        • Tan Woon How

          Hey, you said 2 days so i take my time :D, mind check your email 🙂

  • Justin

    Hi, I would like to create a similar application to yours but with a few modifications however there were problems encountered. Can you help me with this? Hope that you can reply to me so that I can contact you… Your help is important as I am doing this for a project and the submission date is due soon…

    • Tan Woon How

      Hi i’m replied.

      • Justin

        Hi, can I get your email so that I can describe my problems with you easier? Or you prefer me to give you my email? Sorry for the trouble..

        • Tan Woon How

          admin[a]instinctcoder[dot]com

          • Justin

            Hi, I’ve sent you an email please do take a look. Thank you very much.

  • Ayodeji Adelekun

    Sorry i am new in Android when i load it on my Android studio it gives me this error ::

    Error on line 1: Content is not allowed in prolog.
    Please correct the file content
    Frameworks detected: Android framework is detected in the project Configure

    please help me out

  • Epuser

    Hi, Please Help me to get all list, to Custom Listview adapter Textviews

    • Tan Woon How

      Hi
      Please refer to this tutorial http://instinctcoder.com/how-to-call-asp-net-web-api-from-android-studio/ , it’s almost similar to this tutorial but just that is call Web api for crud operation . Inside this tutorial please look at step 7 for customAdapter.

      🙂

      • Epuser

        I use this code alone could bring the entire list Please Help

        • Tan Woon How

          If i understand you correctly you have succeeded get all data display in listview but now you need to have your own customised adapter to display your data. Is that what you want?

          • Epuser

            This data from my database. By iD
            I want to get all the data.
            I’m very please help me.

          • Tan Woon How

            Ya. the link i gave you could help you to achieve what you need to do, but you need to put all these pieces together.

            1. You need to create a “List View Item” layout like what we did above. i.e view_student_entry.xml, put in your icon, 4 textview for date, title, and another 2 i not sure what is that :).

            2. and then base on this link http://instinctcoder.com/how-to-call-asp-net-web-api-from-android-studio/, in the step 7, the customAdapter.java, which populate data into “List View Item”, and which could give you the above result.

            package instinctcoder.webapiclient;

            /**

            * Created by Tan on 7/23/2015.

            * Description: This class is use for populate data into view_student_entry

            */

            import android.content.Context;

            import android.view.LayoutInflater;

            import android.view.View;

            import android.view.ViewGroup;

            import android.widget.ArrayAdapter;

            import android.widget.TextView;

            import java.util.List;

            public class CustomAdapter extends ArrayAdapter {

            public CustomAdapter(Context context, int resource, List student) {

            super(context, resource, student);

            }

            @Override

            public View getView(int position, View convertView, ViewGroup parent) {

            View v = convertView;

            if (v == null) {

            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            v = inflater.inflate(R.layout.view_student_entry, parent, false);

            }

            Student student = getItem(position);

            if (student != null) {

            TextView tvStudentId = (TextView) v.findViewById(R.id.student_Id);

            TextView tvStudentName = (TextView) v.findViewById(R.id.student_name);

            tvStudentId.setText( Integer.toString(student.Id));

            tvStudentName.setText(student.Name);

            }

            return v;

            }

            }

          • Epuser

            You understand me wrong 😉

            if possible, you can connect I give TeamViewer? plsssssss

          • Tan Woon How

            So what is your question?

          • Epuser

            Can you look at my computer ? TeamViewer
            Can you look at the code I wrote ?

          • Tan Woon How

            Admin (a)instinctcoder (dot)com. I go in tomorrow morning. But seriously what is your question ! ! ! ?

          • Epuser

            Я знаю, что я вас беспокоить
            but I expect you to help.
            You connect to my computer, you can solve both problems

          • Tan Woon How

            I still not seen your teaviewer info in my email’s inbox, have you sent it to me?

          • Epuser

            I am waiting for you TeamViewer

          • Epuser

            I am waiting for you TeamViewer

          • Epuser

            I am waiting for you TeamViewer ;))))

          • Epuser

            My codes

          • Epuser

            I know that lists data on the list of simple ListView
            I now want to list the specific list form
            as pictured bottom – bottom

  • Siddiqui, Taha R

    This tutorial is like the best of 100+ tutorials I have seen so far for doing simple CRUD operations. It just cant get any simpler than that. +1 for the code even working for the newer versions. WITHOUT ANY PROBLEMS, in the first run. I tried like 6-7 tutorials before this, got frustrated and left midway.

    • Tan Woon How

      Ha, i guess this tutorial must be lucky enough in your environment to run on first attempt :). Does this deserve 1 FB like from you ? 😀

  • Faizan Uddin

    Hey Buddy ! Me Again.. Again i have to say that Your CODE is Very GOOD ! , I’ve never seen any Database Code like this..
    but there is one Change i want to do in this code..
    i.e I want to Save IMAGE instead of AGE…
    I’m unable to save my IMAGE in Database..
    Please Help..
    I have to Submit the Project Tomorrow ..
    I’ve Tried Everything but nothing to show..

    • Tan Woon How

      Hmmm.. i will not choose to save image into the database . What i will do is only save the path of the image into db. And image save into folder.

      And I’m happy you like this tutorial it’s help me to continue to blog. Lol.. and how about give me 1 FB like ;).

      • Faizan Uddin

        Yes but how? I have already did upload image work, i have a picture in imageView , now how can
        i save that image in Database?

        • Tan Woon How

          I’m not entirely sure what you trying to achieve, if you manage to load file into imageView, meaning you know the path of the image, just save the image path into database, that all. and when you want to retrieve use the path saved into table and load into imageView.

  • Faizan Uddin

    HEY BUDDY ! Your Code is very Helpful, but there is 1 little bug, when i changed age column with ‘PHONE’ i cant give 11 INTEGER NUMBERS in the editText, because when i try to save it after giving 11 INTEGER NUMBERS i.e(03212036661) its shows me error , plz Help … 🙁

    • Tan Woon How

      Hey bro
      You need to change DATABASE_VERSION number and also change the column type to text and try again.

      • Faizan Uddin

        I’ve already change the DATABASE_VERSION number and Column Type to TEXT , but no Success !,,
        then i came to find the Solution.. Here It is.. 🙂

        To Remove By Default Vaue(0) From editTextAge:
        I Changed this LINE “editTextAge.setText(String.valueOf(student.age));” WITH THIS “editTextAge.setText(student.age);”

        To Extends The Limit i.e 10 DIGITS of INTEGER to Unlimited:
        I Changed This LINE “student.age= Integer.parseInt(editTextAge.getText().toString());” WITH THIS “student.age=editTextAge.getText().toString();”

        SOLVED……!!!

        🙂 Thanks For Reply..

        • Tan Woon How

          Hey bro
          You not supposed to use INT type for phone column. Change it to TEXT type. Even you have make the above work but what if the phone number keyed in needed to start with “0”. Then your saved data will be incorrect .

  • Pingback: ANDROID STUDIO > Sqlite, Listview and Onclick basic example | Questions()

  • tee

    Hi, when i clicked Add button, a error shown “Unable to find explicit activity class {com.example.tappmediaadt3.studentlist/com.example.tappmediaadt3.studentlist.StudentDetail}; have you declared this activity in your AndroidManifest.xml?”

    • Tan Woon How

      You read the error, Check you’re AndroidManifest.xml? 🙂

      The long version, each time you added an Activity, you should have these line added into your AndroidManifest.xml, in case your IDE did not automatically add for you, please add these line manually.

      • DBL

        This was very useful for me!! This code was the only part that my code doesn’t generate 🙁 But now works perfectly! Thank you Tan & tee !

    • Rifaz Zulrizqa

      Add this to your manifest.xml code 🙂

  • Mfreyn

    Hey so when I use iCount it appears grey and say variable isn’t called and I’m getting a syntax error near the “FROM” right above the iCount? I have your tutorial working with the way you have it but when i add 2 more columns the first page of the app will appear, but when I hit either button the application will fail. I changed the Database_Version also. Any thoughts could help been stuck here for days

    • Tan Woon How

      Hi
      Paste your query here, i think is cause by your query.

  • Mark

    Hi, thank you for this tutorial! 😀

    The program worked very nice, but I have a problem. I can only add one text. The other texts are not displayed. I get always the same error:

    at com.listview.DbManager.createAlarm(DbManager.java:57) –> long alarm_id = db.insert(DbHelper.TABLE_NAME, null, values);

    at com.listview.DetailsActivity.onClick(DetailsActivity.java:74) –> model.id = Alarm_Id;

    if (Alarm_Id==0){
    Alarm_Id = manager.createAlarm(model);

    Toast.makeText(this,”New Student Insert”,Toast.LENGTH_SHORT).show();
    }else{…
    y

    In the picture you can see that I can display only one text.
    Thank you for the help!

    • Tan Woon How

      Hi
      Could you paste the error message also? You provide me only the error stack trace. I not sure why you can only see 1 word. So may be fixing the error will help.

  • Антон Бушин

    A good lesson ! Everything worked out. A small hitch occurred here in this place
    public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_student_detail, menu);
    return true;
    }

    menu in this line
    R.menu.menu_student_detail
    but , all right , it was not difficult.
    Thank you for this lesson!

    • Tan Woon How

      Thanks for dropping by. Arhh… OK, I will remove these lines from the post, since it give problem to many of you. :). These line are auto generated by IDE and it doesn’t give me problem so i just leave it. BUT, cause you guys problem…

  • Justin

    Hi, I follow all the steps and try but when I try to run the program it shows “Unfortunately, SQLiteDB has stopped” message. Do you know how to fix this? Hope to get your help soon as I’m doing a project. Thanks!

    Below is the logcat error message.

    10-27 03:11:11.776 24545-24545/? D/dalvikvm﹕ Late-enabling CheckJNI

    10-27 03:11:13.732 24545-24545/edu.np.ece.sqlitedb D/AndroidRuntime﹕ Shutting down VM

    10-27 03:11:13.748 24545-24545/edu.np.ece.sqlitedb W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa6190908)

    10-27 03:11:13.780 24545-24545/edu.np.ece.sqlitedb E/AndroidRuntime﹕ FATAL EXCEPTION: main

    java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.np.ece.sqlitedb/edu.np.ece.sqlitedb.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

    at android.app.ActivityThread.access$600(ActivityThread.java:141)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

    at android.os.Handler.dispatchMessage(Handler.java:99)

    at android.os.Looper.loop(Looper.java:137)

    at android.app.ActivityThread.main(ActivityThread.java:5041)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:511)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

    at dalvik.system.NativeStart.main(Native Method)

    Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

    at android.app.ListActivity.onContentChanged(ListActivity.java:243)

    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)

    at android.app.Activity.setContentView(Activity.java:1881)

    at edu.np.ece.sqlitedb.MainActivity.onCreate(MainActivity.java:62)

    at android.app.Activity.performCreate(Activity.java:5104)

    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

    at android.app.ActivityThread.access$600(ActivityThread.java:141)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

    at android.os.Handler.dispatchMessage(Handler.java:99)

    at android.os.Looper.loop(Looper.java:137)

    at android.app.ActivityThread.main(ActivityThread.java:5041)

    at java.lang.reflect.Method.invokeNative(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:511)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

    at dalvik.system.NativeStart.main(Native Method)

    • Tan Woon How

      HI,

      You need to change your ListView id to android:id=”@android:id/list”. So the XML should look like something this

      • Justin

        Hi, now I’ve solved the problem and the application is able to start. A very big thank you to you but I encounter another problem again. Even though the application is able to start now, when I press the Add button the application stopped again. May I know why? Below is the error message:

        10-27 10:38:48.862 1753-1753/edu.np.ece.sqlitedb E/AndroidRuntime﹕ FATAL EXCEPTION: main

        java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.np.ece.sqlitedb/edu.np.ece.sqlitedb.StudentDetail}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)

        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

        at android.app.ActivityThread.access$600(ActivityThread.java:141)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

        at android.os.Handler.dispatchMessage(Handler.java:99)

        at android.os.Looper.loop(Looper.java:137)

        at android.app.ActivityThread.main(ActivityThread.java:5041)

        at java.lang.reflect.Method.invokeNative(Native Method)

        at java.lang.reflect.Method.invoke(Method.java:511)

        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

        at dalvik.system.NativeStart.main(Native Method)

        Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

        at android.app.ListActivity.onContentChanged(ListActivity.java:243)

        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:273)

        at android.app.Activity.setContentView(Activity.java:1881)

        at edu.np.ece.sqlitedb.StudentDetail.onCreate(StudentDetail.java:25)

        at android.app.Activity.performCreate(Activity.java:5104)

        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)

        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)

        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)

        at android.app.ActivityThread.access$600(ActivityThread.java:141)

        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)

        at android.os.Handler.dispatchMessage(Handler.java:99)

        at android.os.Looper.loop(Looper.java:137)

        at android.app.ActivityThread.main(ActivityThread.java:5041)

        at java.lang.reflect.Method.invokeNative(Native Method)

        at java.lang.reflect.Method.invoke(Method.java:511)

        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)

        at dalvik.system.NativeStart.main(Native Method)

        • Tan Woon How

          Hi
          It’s look like same error. You have listview in StudentDetail ? If yes you need to do the same as before . If you don’t need listview in detail screen please don’t extends it.

          • Justin

            Hi, thank you very much you helped to solve the problem. Cheers and have a nice day!

  • Amanda Lail

    Hi, me again. I fixed the onClick() error I was getting. Now I can click on the item. When I do click on the item, it launches the activity correctly, but doesn’t have my information that I saved into the item showing. Do you know how to fix this? Thank you for all the help!

    • Tan Woon How

      Hi great you solved it. You got to make sure you have passed in data when save and also when click on item do you able to see the id when debug?

  • Jean Durieux

    Hi
    Thank you for this tutorial
    I use Android Studio 1.4
    When I launch the app, the (Simple List Item) ListView is empty, the text “No student!” doens’t appear
    When I click on the button Add or the button GetAll, I have this error:

    android.database.sqlite.SQLiteException: no such column: name (code 1): , while compiling: SELECT id,name,email,age FROM
    Student WHERE id=?

    Thank you for your help

    • Tan Woon How

      Hi,

      Please make sure you have “name” column created. If you’re using the same class name “DBHelper”, you need to change this number each time you add/edit column of table.
      private static final int DATABASE_VERSION = 4;–> Increase this number when you edit table.

      and also check your table schema, whether you have “name” column.

  • Amanda Lail

    Hi, I am having problems with onClick() when clicking on the items in the list. The items are showing in the list but when I try to click on them I am getting an error. The error is Invalid int “”. The app shuts down after clicking on an item. Can you please help?

    • Tan Woon How

      Hi, Base on the error, i think you assigned “” into Integer variable

      • Amanda Lail

        I can’t seem to find it. Can I send you my code?

        • Tan Woon How

          I try to answer question here, so if others encounter same issue they could find the answer here. Could you paste code here that you encountered error?

          • Amanda Lail

            Here is my onClick method in Main Activity. Its the same as yours I believe. I am getting an error at Integer.parseInt(student_Id).

            @Override
            public void onClick(View view) {
            if (view== findViewById(R.id.btnAdd)){

            Intent intent = new Intent(this,StudentDetail.class);
            intent.putExtra(“student_Id”,0);
            startActivity(intent);

            }else {

            StudentRepo repo = new StudentRepo(this);

            final ArrayList<HashMap> studentList = repo.getStudentList();
            if(studentList.size()!=0) {
            ListView lv = getListView();
            lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view,int position, long id) {
            student_Id = (TextView) view.findViewById(R.id.student_Id);
            String studentId = studentId.getText().toString();
            Intent objIndent = new Intent(getApplicationContext(),StudentDetail.class);
            objIndent.putExtra(“student_Id”, Integer.parseInt(studentId));
            startActivity(objIndent);
            }
            });
            ListAdapter adapter = new SimpleAdapter( MainActivity.this,studentList, R.layout.view_student_entry, new String[] { “student_id”,”name”}, new int[] {R.id.student_Id, R.id.student_name});
            setListAdapter(adapter);
            }else{
            Toast.makeText(this, “No student!”, Toast.LENGTH_SHORT).show();
            }

            }
            }

          • Tan Woon How

            Hi,

            Try look back at the code where you retrieve data, (Try debug step by step), Your textView (student_Id) didn’t populated with data. If you have the same function name as mine that use to retrieve student record (getStudentList();) please look into that function, see you miss any.

  • Jocelyn Chong

    Hi, may I know how should I edit the source code by clicking the “Save” or “Delete” button in the student detail layout for refreshing to the updated data and show it in the main activity layout , instead of click the “ListAll” button in the main activity layout? Thanks.

    • Tan Woon How

      You could use onResume in main activity and adapter.notifyChanged ()

      • Jocelyn Chong

        Its work, thanks a lot..
        Besides, I want to setup “Add” button to action bar, so means that I needs to extends ActionBarActivity in Main Activity, also I want to extends ListActivity in Main Activity for displaying my data list view. However Java unable to set multiple inheritance. So can I know how should I do? Thanks again..

        • Tan Woon How

          You could use listview without inherit listview in the Activity.

  • Christian González

    Hola amigo, gran tutorial. Solo un pequeño error que me dio. ¿Por que a la hora de mostrar el nombre de la persona en el ListView, me sale asi, pero cuando hago click si me muestra los datos en el otro Activity?

  • Matheus Henrique

    Bro, awesome tutorial, but I’m having an error:
    Everytime I click on a person in the listView, it opens an activity with the first person from the list. For instance, I added 3 people in the list, but no metter on wich one I click, it will open a window with the info for the first person I added 🙁

    • Tan Woon How

      Hi
      I think you’re close. Please check ID pass in to query function to retrieve the record i guess may be your query did not filter the Id passed in

  • Leora Cigler

    I am getting an error:cannot find symbol variable main

    The code

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }

    • Tan Woon How

      You could remove this function is not relate to this tutorial . Is just a menu.

  • Emmanuel Enkirche

    Hi, i use your code for an personnal project. Thank’s for this. I meet a problem, with one line : Student student = new Student (); :
    “Variable ‘student’ with intializer ‘new Student()’ is redundant.
    I don’t understand this error, in my work, i only modify the name variable and class. Whoat do you think of that. Thank’s

  • Alee Saeed

    Brother I want to interact my app with Web Server. :/

  • Rthapali

    Hey, I am getting error at StudentDetails class. While creating onCreateOptionsMenu method because I don’t have R.menu.student_detail. Can you tell me what to do for menu.student_detail?

    • Tan Woon How

      Hey,

      You could remove that line as it’s auto generate when you create StudentDetail.java and it is not necessary for this tutorial. I not sure why your IDE not created the menu for you by right it should auto generate that menu, anyway i think i will remove it later.

      • Rthapali

        Thanks Tan. Yes you are right that was not necessary for the code to work.
        I also have another question.If I add things and delete all of them, then also it is being shown on the listview(only the last data to be deleted). But pressing Listall gives me toast message saying the list is empty. Despite of that, I still can see the last data which I had deleted.

        • Tan Woon How

          Hmm.. Check your delete and listAll query. May be you missed out something there.

          • Rthapali

            Tan I looked everything. Everything gets deleted from database, I also get empty list Toast message when I press ListAll. But the last item deleted is still shown on the list. Once I add one data, then that deleted item goes away.

        • Rifaz Zulrizqa

          solved, i just adding the syntax to reset listView when “studentList.size is 0” 🙂

  • Pingback: Tutoriales android | Blog de Mario Javier()

  • Nikesh Kumar B K

    Mr.Tan Woon can you explain how to work with multiple tables

    • Tan Woon How

      Hi Nikesh,

      Basically it work the same as single table. and you need to declare your new table in the DBHelper.java. and you could code your query in the studentRepo.java, but first thing you need to understand the SQL statement first, so i suggest you this link https://www.sqlite.org/lang.html. Hope this help! Hmm.. do you think a sample help you better? May write one for multiple table… You’re the 2nd reader asking about multiple table..

      • David Reinerts

        That would be very nice, I have the same problem.
        And perhaps you can tell me where I can find the database file. There is no file
        in the data/data/mypackage/databases directory.
        Thank you 🙂

        • Tan Woon How

          Hi David,

          If you follow this tutorial, by right, it should save in this directory of phone/emulator, “data > data > SQLiteDB > databases > crud.db”, if you like to browse data and table structure of the database you could refer to http://instinctcoder.com/how-to-browse-android-emulator-sqlite-database/ (Sorry, this link is show in Eclipse, but it should be about the same, I will make 1 for Android Studio too)

          OK, my next assignment will be SQLIteDB multiple table app. Stay tuned!

  • Pingback: ANDROID STUDIO > Sqlite, Listview and Onclick basic example - BlogoSfera()

  • Manish Tapadar

    In the MainActivity.java file the line is”
    getMenuInflater().inflate(R.menu.main, menu);”

    In this line a error is thrown that “cannot resolve symbol main”
    What should I do for that?

    • Tan Woon How

      Hi
      you could remove that line if your compiler did not generate for you . As this is an auto generate code.

  • how can create Spinner view in android studio
    if you are beginner and do not know how to create a spinner view in android then this lecture can help a lot
    http://themasterworld.com/android-spinner-example/

  • Vincent

    Hi, Tan Woon How
    i used your example to make a note application for an assignment ( i need to submit it this thursday )
    i have been struggling with the database and finally , it worked but the listview still show nothing
    can you help me ?

    • Tan Woon How

      Hey Vincent,

      Tell me where you stuck.

      • Vincent

        well , i also don’t really know but it should be around insert method or list view
        should i send my project to you so you can analyze it better ?

        • Tan Woon How

          OK, let me have a look, send to admin[@]instinctcoder.com

          • Vincent

            Sorry, Tan Woon How
            is it alright if i just copy the script into notepad and send it to you ?
            the upload keeps failing

          • Tan Woon How

            May be you need to change your file.zip to file.txt. 🙂 Just guessing. Don;t send me notepad, you’re killing me!

          • Vincent

            Never mind, it uploaded successfully
            i compressed the project into rar file and sent
            please check your email

          • Tan Woon How

            I didn’t receive your email.

          • Vincent

            i send the email to [email protected] one more time
            please check it again

          • Tan Woon How

            Hmmm.. Please try learn debug the code, you did everything just fine just that you need to debug your code. May be i make one tutorial for you :). Good luck and stay tuned !

            And could you not put my email so obvious please change @ to [@] thanks.

          • Vincent

            sounds like more work more for me and i am running out of time @[email protected]
            can you point out which part of my code must be debugged ?

          • Tan Woon How

            Check your email, i think gmail block the file

            About Debug, you need to place breakpoint in your code where you suspect causing crashed and click “BUG” icon (Alt+Shift+F9) and then you step into 1 by 1 (F7) and check the error.

          • Vincent

            Did you send something to me ?
            I didn’t receive anything

          • Tan Woon How

            No problem, A “Like” will help me 🙂

  • Snêha Siñgh

    when i ran your program i am getting an error sir saying that the DBHelper class should provide a default constructor..i don’t know what mistake i did..please help me out

    • Tan Woon How

      Hi

      Which version of compiler are you using? Try add to the one it complained, meaning add this

      public DBHelper( ) {
      }

      • Snêha Siñgh

        sir i am working on a new application for jack prodigy of our college which will allow teachers to take attendance from app itself plus it will also send the broadcast messages at short notice to assemble anywhere in case of emergency.so just guide me..would need your help

        • Tan Woon How

          Err…. i try my best ?

  • Anthony Snow

    Hello, how are you, I am having a hard time understanding what is going on when you use “=?”. What does that mean?

    • Tan Woon How

      Hi Anthony,

      Take this line as example
      db.update(Student.TABLE, values, Student.KEY_ID + “= ?”, new String[] { String.valueOf(student.student_ID) });

      ? –> this is just a symbol that will going to replace by the value of student.sudent_ID.

      If you not prefer to use the symbol, you can remove it and concatenate the value like this
      db.update(Student.TABLE, values, Student.KEY_ID + “= ” + student.student_ID , null);

      But, it is always a good practice that we use “?” in the query, as it will taking care the column’s type for you (“Text” or “Integer”) and you won’t need to check what type of column when you write the query. Not sure If you aware, when you concatenate with “Text” column in query you need to surround the value with single quote (‘). For example,

      db.update(Student.TABLE, values, Student.KEY_Name + “= ‘” + student.student_Name + “‘”, null);

      Hope i answer you 🙂

      Thanks for popping up!

      • Anthony Snow

        Thank you I appreciate it very much. and the “new String[] {String.valueOf(student.student_ID)}); ” parameter is just turned to null?

        • Tan Woon How

          You mean the concatenate version ? yes. Because no value to pass in

          • Anthony Snow

            okay I’m starting to understand. Thank you very much for your help i appreciate it

          • Tan Woon How

            No problem 🙂

  • Tabeer

    hi my name is Tabeer, please tell me how can i delete or update data by press and hold the item.

    • Tan Woon How

      Hi Tabeer,

      I don’t quite get you “by press and hold them item”? Could you elaborate a bit more?

  • Mateo Duque

    Hola amigo me podrías decir como programo cuatro botones (Primero, anterior. siguiente y Ultimo)
    los datos los muestro en text pero es necesario que el usuario se mueva entre los registros es decir presionando botones, una manito por favor, Saludos desde Colombia

  • Asad Sumon

    I want to click a data and then (When show all data) i edit or delete the selected data. how can i do it????

    • Tan Woon How

      Do you mean you want to edit or delete data direct in the ListView ? You need to create a custom xml for listviewitem and is like what we did in this tutorial view_student_entry.xml

  • Molly

    public void onClick(View view) {

    if (view == findViewById(R.id.btnAdd)){

    Intent intent = new Intent(this, DVDDetail.class);

    intent.putExtra(“dvd_Id”, 0);

    startActivity(intent);

    } else {

    DVDRepo repo = new DVDRepo(this);

    ArrayList<HashMap> dvdList = repo.getDVDList();

    if(dvdList.size() != 0) {

    ListView lv = getListView();

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override

    public void onItemClick(AdapterView parent, View view,int position, long id) {

    dvd_Id = (TextView) view.findViewById(R.id.dvd_Id);

    String dvdId = dvd_Id.getText().toString();

    Intent objIndent = new Intent(getApplicationContext(), DVDDetail.class);

    objIndent.putExtra(“dvd_Id”, Integer.parseInt( dvdId));

    startActivity(objIndent);

    }

    });

    ListAdapter adapter = new SimpleAdapter

    ( MainActivity.this, dvdList, R.layout.dvd_entry, new String[]

    { “id”,”title”}, new int[] {R.id.dvd_Id, R.id.dvd_title});

    setListAdapter(adapter);

    }else{

    Toast.makeText(this,”No DVD!”,Toast.LENGTH_SHORT).show();

    }

    }

    }

    I put the code into my Android Studio and changed it from a student database to a dvd database but this code is what is giving me a hard time. How would I fix this?

    • Tan Woon How

      Hey Molly,
      Thanks for dropping by.
      The code looks good to me, i can’t see any odd thing. So mind to tell me what error you are getting? and which line is causing error?

    • Tan Woon How

      Hi Molly,

      When i run your project, i got this error in logcat when i click “List All” button,

      Error from logcat
      FATAL EXCEPTION: main
      Process: com.nsu.molly.dbmidterm, PID: 12463
      android.database.sqlite.SQLiteException: near “,”: syntax error (code 1): , while compiling: SELECT id,title,cast,description,genre,price,year FROM DVD

      sometimes error report is not quite relevant, so you need to check your DBHelper to spot any mistake on that table and i found you mistake in these

      1. String CREATE_TABLE_DVD = “CREATE TABLE ” + DVD.TABLE , you put DATABASE_INFO, and you try to query DVD.TABLE

      2. DVD.KEY_cast, change “cast” to other name because cast is reserved word should not use as column name.

      I got error when i click “Add” button, and because you try to populate NULL value into editText quick solution is don’t retrieve data for “Add”.

      And i found more errors when i reached Detail screen i leave it to you, and if you need more help please let me know. Please try it first before asking again, by doing this at least you learn 🙂

      Cheers..

      • Molly

        Okay I am trying! I have changed the things you said but I am still stuck /:

        • Tan Woon How

          check your email

  • MG

    Dear Tan I tried making this tutorial and have no errors in the code.When i emulate this the the main screen appears but crashes once i click on the buttons?? can i send you my project and can you help me what i did wrong in this. Thank you

    • Tan Woon How

      Hi MG,

      From the error, it seem like you’ve not created “Movie” table, please make sure you have create table before query, if you still having the same error, you could send to me to have a look. admin[at]instinctcoder.com

      • MG

        Hey Tan
        I’m still getting errors, I have send you the file can you please have a look at it and send it back with what is wrong in it. Thank You

        • Tan Woon How

          Great you have solved the first one. You need to increase the version number each time you have any changes in column name or adding new table. The .txt content i think is not adequate to discuss here.

    • Molly

      Tan, this is the error I am having as well… how do I fix this… mine is with DVDs.

      • Tan Woon How

        Molly, his error is because when he add his own table but not change the version number and sqlite doesn’t know there is a new changes in the table schema, so what he did is just increase the version number each time change the column name, add column/ tables.

        For e.g. each time you need to increase this number .

        private static final int DATABASE_VERSION = 4;<—increase to 5 when there is a changes

        But you may have different error from what he encountered, so please check your logcat, and if you need help just drop me a comment 🙂

        • Molly

          Hello, can I just send you all the code so maybe then you can get a better understanding?

  • Vhox

    Dear Tan How. Everything was fine with the code, but when I try to run the app (in a android device or in a virtual simulator) the apps crashes. A message: “unfortunately, the app stops apperars on the screen.”

    Could you help me? I use Android Studio, lastest version.

    This is whats is shown in the logcat:

    04-07 03:26:56.821 1892-1892/br.com.compex.www.sqlitedb E/AndroidRuntime﹕ FATAL EXCEPTION: main

    Process: br.com.compex.www.sqlitedb, PID: 1892

    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.compex.www.sqlitedb/br.com.compex.www.sqlitedb.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

    at android.app.ActivityThread.access$800(ActivityThread.java:144)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

    at android.os.Handler.dispatchMessage(Handler.java:102)

    at android.os.Looper.loop(Looper.java:135)

    at android.app.ActivityThread.main(ActivityThread.java:5221)

    at java.lang.reflect.Method.invoke(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:372)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

    at android.app.ListActivity.onContentChanged(ListActivity.java:243)

    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:381)

    at android.app.Activity.setContentView(Activity.java:2144)

    at br.com.compex.www.sqlitedb.MainActivity.onCreate(MainActivity.java:68)

    at android.app.Activity.performCreate(Activity.java:5933)

    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)

    at android.app.ActivityThread.access$800(ActivityThread.java:144)

    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)

    at android.os.Handler.dispatchMessage(Handler.java:102)

    at android.os.Looper.loop(Looper.java:135)

    at android.app.ActivityThread.main(ActivityThread.java:5221)

    at java.lang.reflect.Method.invoke(Native Method)

    at java.lang.reflect.Method.invoke(Method.java:372)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)

    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    • Tan Woon How

      Hi vhox
      According to the error. I think you need to change the ListView id to android:id=”@+id/listView” if you choose to extends ListActivity in your class.
      Try again and let me know 🙂

      • Vhox

        Dear Tan.

        Maybe I did not understand well, but I think I already did it. This is my xml to the list view:

        Is it correct? Thanks for all your attention.

        • Tan Woon How

          yes is correct . let me have a look please send your code to my admin(at)instinctcoder.com

          • Vhox

            Thanks, Tan. I just sent it.

          • Tan Woon How

            Opppss.. ! Sorry for replied you WRONG earlier, You need to change your ListView id to android:id=”@android:id/list”. So the XML should look like this

            i replied your email together with your project.

          • Vhox

            Dear Ton. Thanks a lot. Now it works! Also, I try to keep on studding in your example and decided to add new fields with other informations to register.

            I believed it won’t be any trouble, but now when I try to access any register in the list view, it crashes the app. In the log cat, it’s showed: 04-08 15:30:12.341 3237-3237/br.com.compex.www.sqlitedb E/CursorWindow﹕ Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 6 columns.

            I sent u a new email with the project modified. I so grateful with your answers!

            Best regards!

          • Tan Woon How

            Hi, Anyone here name Ton, Not me 🙂

            In your SQL statement you miss out this Student.KEY_age + “,”,

            The complete line should be like this

            String selectQuery = “SELECT ” +

            Student.KEY_ID + “,” +

            Student.KEY_name + “,” +

            Student.KEY_email + “,” +

            Student.KEY_empresa + “,” +

            Student.KEY_departamento + “,” +

            Student.KEY_age + “,” +

            Student.KEY_obs +

            ” FROM ” + Student.TABLE

            + ” WHERE ” +

            Student.KEY_ID + “=?”;//

          • Vhox

            Dear Tan! Thanks a lot. It was my mistake! Best regards and thanks for all your help!

  • Lester Barrientos Toruño

    bro the button btnGetAll is dont work. I don’t know why dont work. You can help me? The error is setListAdapter and getListView.

    • Tan Woon How

      Could paste the error here from logcat?

    • carmenrosales

      You need extends ListActivity in the class

  • Ben Han

    Hi, please can you help me;
    I have this error when I run my project:
    Failed to install SQLiteDB.apk on device ’emulator-5554
    thanks

    • Tan Woon How

      could you check the logcat error? the error you given is to general.

      • Ben Han

        now; I have this error when i click add:
        Could not find class
        ‘com.instinctcoder.sqlitedb.StudentDetail’, referenced from method
        com.instinctcoder.sqlitedb.MainActivity.onClick

        and “Unfortunately
        SQLiteDB has stopped”

        • Tan Woon How

          Check inside your project have this file or not? Did use the download copy?

          • Ben Han

            Yes i have this file in my project

          • Tan Woon How

            Well my best guess is either you declare a private the class or typo error check carefully cause java is case sensitive. If still getting same error send send to my admin(at)instinctcoder.com let me have a look .

          • Tan Woon How

            Hi Ben,
            I studied your code and is build in Eclipse and the reason you getting this error is because in this tutorial we’re using standard template (android-support-v4.jar and android-support-v7-appcompat.jar) which come in android studio but in Eclipse you need to import that manually, detail and source code available as above updated section.

            Try again and let me know , ya 🙂

  • Eli Stein

    Hi Tan Woon How
    Thans for your fast reply.

  • Eli Stein

    Hi Tan Woon How
    Thanks a lot for your nice tutorial .
    After correcting some errors, the programme came clean, but it says “Unfortunately
    SQLiteDB has stopped” . My guess is that I didn’t understand your following instructions”

    “You need to change the ListView id to android:id=”@+id/listView” if you choose to extends ListActivity in your class or else you will get error –> Your content must have a ListView whose id attribute is ‘android.R.id.list’ ”
    Can you pls clarify .
    Thanks in advance

    • Tan Woon How

      Hi Eli Stein
      This because in our mainactivity.java we have extend listactivity so that is why in xml file must specify the keyword android while mentioning to a ID.

  • john

    when i click the button ‘add’, the application will stop working..

    • Tan Woon How

      Hi john. Can’t help you if you not provide me details. Could you have a look at logcat? Tell us what error you’re getting .

  • Muammar Geias

    i have problem at student detail

    • Tan Woon How

      Yes? tell me

      • Amir Khan

        i also have the same problem. inside the StudentDetail.java
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.student_detail, menu);
        return true;
        }

        the student_detail is red

        • Tan Woon How

          Hi Amir,

          Hmm… that line of code is auto generate. you could comment it to continue the tutorial.

          By right the “student_detail.xml” menu should auto generate in this folder src > main > res > menu > when you create your activity “activity_student_detail.xml”. This content of the file is look like this


          If you could download the source code from above link. You should able to see what i mean.

  • Gutenberg Alexis

    Thanks, works perfectly!

    • Tan Woon How

      You’re Welcome!!! 🙂

      • Ah FaliHah

        Hi,can you help me..i having trouble in make a database that have multiple table in it.i hope u can give some example.

        • Tan Woon How

          Above sample could work with multiple table, just add more table and the rest you just need to join it. Tell me more see i could help

  • George Zoiade

    how can I implement a spinner and a datepicker in this type of database ?

    • Hmm.. sorry to reply late. I do not have one now. i try work out one for you 🙂 this week. For quick one, you could refer to this link for startup. http://developer.android.com/guide/topics/ui/controls/spinner.html. Hope you still have time for my spinner tutorial.:)… Too lazy lately, have addicted to “Castle Clash”… lol

    • Tan Woon How

      Hmm.. sorry to reply late. I do not have one now. i try work out one for you this week. For quick one, you could refer to this link for startup. http://developer.android.com/guide/topics/ui/controls/spinner.html. Hope you still have time for my spinner tutorial.:)… Too lazy lately, have addicted to “Castle Clash”… lol

    • Tan Woon How

      Still there? :). anyway i just write a spinner sample code with sqlite database. If you like to have it please get it from here> https://www.dropbox.com/s/4stpiwm0wjnzy73/SpinnerSqlite.rar?dl=0. A complete step by step explanation will be ready soon..(hopefully i not dragging by “Castle Clash” again…

      • George Zoiade

        Thx man appreciate 🙂

        • Tan Woon How

          No problem at all.. :). Help you n you help me XD

  • Vivek

    thx for this nice example

  • bat

    I succeeded in making the app run but I had to make some modifications in your code. Here it is, for the sake of people getting their app run 😉

    Anyway, Tan, I THANK YOU VERY MUCH :)))))

    NB: My packages are of course different than those of the tutorial!

    MainActivity.java

    DBHelper.java

    Student.java

    StudentDetail.java

    StudentRepo.java

    AndroidManifest.xml

    view_student_entry.xml

    activity_main.xml

    activity_student_detail.xml

    build.gradle

    • Tan Woon How

      Hi bat
      Thanks for your comment. Im happy the tutorial helps… will continue to provide more android example in coming free time ☺. Now too busy on work.

  • bat

    Many thanks for your tutorial!

    When clicking “List All”, I would like the email & age to appear as well there… May I kindly ask you how I may achieve this?!

    I tried to add in view_student_entry.xml the following TextView

    below

    …but it does not work 🙁

    Could you help me please?!

    Thank you!

    Bat

  • Daniel Briones Reyes

    could someone tell me if it worked? and try anyway wrote letter by letter, import the project, and I mark errors and does not run, missing something? took 3 days and trying to prove anything, Greetings

    • Tan Woon How

      Hmm.. could you let me know what error you’re getting? and also there is a complete download project available up there, have you try?

  • ‘Prasad D. Madusanka’

    StudentDetail.java file is wrong. Please update it quickly 🙂

    • Tan Woon How

      Oppss…!!! Thanks for reporting the mistake, Updated. Hope you find this tutorial/example is helpful.