Android Development 14

Android Development TutorialWelcome to part 14 of my Android Development tutorial! In this part of the tutorial I will completely finish the Android Address Book App. I will also spend a lot of time answering questions I recently received on Contexts, Intents, how to pass data between Activities using putExtra() and and getStringExtra(). I’ll also cover how to import Android packages into Eclipse.

Here is the final complete Android Address Book App Package. All of the specific code I worked with in this tutorial can be found below.

If you like tutorials like this, it helps to tell Google+ with a click here [googleplusone]

Code From the Video

EditContact.java

109 thoughts on “Android Development 14”

  1. Hi Derek

    I saw someone asking you to do a UI like Feedly reader’s UI. The only thing exotic on Feedly reader UI is its sliding menu part. And I am interested in that too. I wonder if you could implement a sliding menu tutorial. Also, you have done xlm parsing. Can you do a JSON parsing app too. Thanks.

    Mike

    1. I’m going to cover fancy menus and much more. Sure I can cover JSON parsing. I should have done it in the previous tutorial. I may just add it on now. I don’t know if that would confuse people or not?

  2. Thank u so much for the excellent tutorials.

    There is an issue in callMainActivity. After u add a new contact, it does not go back to the existing MainActivity. It always creates a new MainActivity instance. If u press the Back button, it goes back to NewContact.

    I suggest getting the result of NewContact activity and then refreshing MainActivity. http://developer.android.com/training/basics/intents/result.html

    1. Vince,

      Could you sent me the solution with regards to the
      issue in the callMainActivity ?

      Thank you,

      Anton

  3. Hi Derek. I have been watching your Android tutorials since you released your first one. Since then I have been hooked on developing for Android and I have released 3 apps. The first one is a simple app for tracking your income and expenses, and gives an overview in the form of a pie chart and a bar chart. The other two is quiz apps, flag quiz and soccer quiz. Although I’m mainly developing for fun and experience it would be cool if someone actually downloaded my apps. Do you have any marketing tips to get people to notice your apps? Be it Play Store search rankings or other tricks. I know my apps isn’t exactly the only of its kind, but I’m certain I would get more downloads if people actually noticed my apps. Being on the 20th page of search doesn’t exactly help me get attention.

    1. Wow, I’m happy that the videos have helped that much! Great Job! As per marketing the apps I’d say you’re better off trying to make a YouTube video about them using keyword tricks. I mainly make Android apps for private companies so I have never had to market on the Android marketplace.

      Try using the Google keyword tool to find keywords that are in high demand, but have a low level of competition.

      I went there and typed in the following
      android expense tracker app
      best expense tracker app for android
      spending tracker app android

      Based off the results a YouTube video on your app named “on track app for android” might work if your app is named On Track?

      I think YouTube is the best way to market for free online. It is very hard to use keywords to drive traffic anymore to a regular site. As more people start using YouTube to market seriously though that will probably no longer be true.

      I hope that helps

      1. Thanks. That tool is actually a really good resource. I’ll definitely look into uploading some videos on Youtube.

    1. I provide all of the code in a complete package that you can download. I show everything that needs to be changed over the course of the tutorials. Sorry if they were confusing. I’ll do my best to improve πŸ™‚

  4. Hi Derek,

    sorry to bother you with a question, but I’m having an issue with an application that I’m doing in android.

    the thing is that the application was coded and is working on my smartphone (android 4.1.2) and other devices with this version of android.
    the thing is that when I try it on a device with android 2.3.7, the application fails when I’m going to the second activity.

    I debugged the application, and it fails on the “onCreate” method (Screenshot: http://screencast.com/t/Kl5CsMdptN7F) the error is happening in the selected line)

    the strange thing is that a similar method is being used for inflating the previous activity, but it seems that is working fine there…

    if it works, the manifest for the app is set to Min SDK Version = 8.

    please let me know if this information is enough, or if you want me to share my project folder for you to check.

    I’m sorry if I’m going to far with this, but I tried to google how to do this and I’m not getting anywhere.

    thank you and my best regards. I appreciate a lot what you do for us newbies.

    GastΓ³n-

    1. Hi GastΓ³n

      Do you have a layout xml file named activity_uniflow_results.xml?

      Without one you would get an error, but if you do have one I don’t think that line is were your error lies.

      I hope that helps
      Derek

      1. Yes, I have the .XML file, and the error was there, I was using a “space” element in my GUI, and I found out that this method was implemented in the 14 SDK version, hence it was not working with android 2.3 (SDK 8). I changed the Space for a View and it started working πŸ™‚

  5. Receiving error “addressbookapp has stopped unexpectedly “. I ran your contactsapp on the same avd using eclipse but in your case its working fine .What am I doing wrong?
    You dint mention changing the android manifest file but I changed that as well.All the code and layouts are entirely same.

      1. Hi Derek,

        Good Day to you!

        I have also followed your tutorials from Tutorial 10 to Tutorial 14. I am able to run the addressbookapp but after I click on the “ADD” button on the “Contact List” page, the app also stopped unexpectedly with the follow error message “Unfortunately, Contact List has stopped.”

        Below is the info from the LogCat panel:
        08-12 01:28:45.745: E/Trace(873): error opening trace file: No such file or directory (2)
        08-12 01:28:46.305: D/dalvikvm(873): GC_CONCURRENT freed 43K, 7% free 2777K/2964K, paused 13ms+11ms, total 77ms
        08-12 01:28:46.496: D/gralloc_goldfish(873): Emulator without GPU emulation detected.
        08-12 01:28:48.075: D/AndroidRuntime(873): Shutting down VM
        08-12 01:28:48.075: W/dalvikvm(873): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
        08-12 01:28:48.115: E/AndroidRuntime(873): FATAL EXCEPTION: main
        08-12 01:28:48.115: E/AndroidRuntime(873): java.lang.IllegalStateException: Could not execute method of the activity
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.view.View$1.onClick(View.java:3599)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.view.View.performClick(View.java:4204)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.view.View$PerformClick.run(View.java:17355)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.os.Handler.handleCallback(Handler.java:725)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.os.Handler.dispatchMessage(Handler.java:92)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.os.Looper.loop(Looper.java:137)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.ActivityThread.main(ActivityThread.java:5041)
        08-12 01:28:48.115: E/AndroidRuntime(873): at java.lang.reflect.Method.invokeNative(Native Method)
        08-12 01:28:48.115: E/AndroidRuntime(873): at java.lang.reflect.Method.invoke(Method.java:511)
        08-12 01:28:48.115: E/AndroidRuntime(873): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
        08-12 01:28:48.115: E/AndroidRuntime(873): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
        08-12 01:28:48.115: E/AndroidRuntime(873): at dalvik.system.NativeStart.main(Native Method)
        08-12 01:28:48.115: E/AndroidRuntime(873): Caused by: java.lang.reflect.InvocationTargetException
        08-12 01:28:48.115: E/AndroidRuntime(873): at java.lang.reflect.Method.invokeNative(Native Method)
        08-12 01:28:48.115: E/AndroidRuntime(873): at java.lang.reflect.Method.invoke(Method.java:511)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.view.View$1.onClick(View.java:3594)
        08-12 01:28:48.115: E/AndroidRuntime(873): … 11 more
        08-12 01:28:48.115: E/AndroidRuntime(873): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.newthinkjuly.addressbookapp/com.newthinkjuly.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml?
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Activity.startActivityForResult(Activity.java:3370)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Activity.startActivityForResult(Activity.java:3331)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Activity.startActivity(Activity.java:3566)
        08-12 01:28:48.115: E/AndroidRuntime(873): at android.app.Activity.startActivity(Activity.java:3534)
        08-12 01:28:48.115: E/AndroidRuntime(873): at com.newthinkjuly.addressbookapp.MainActivity.showAddContact(MainActivity.java:72)
        08-12 01:28:48.115: E/AndroidRuntime(873): … 14 more

        Just wonder, do you have any idea or suggestions on how I should go about in resolving this error and have the app running?

        Feel free to let me know if there are any other info you may require?

        Thank you

        Best Regards,
        Chen

        1. Hi Chen,

          When you look at the LogCat, always look for your classes in the errors. A lot of junk errors are showing there. Based on what you sent, look here for errors

          08-12 01:28:48.115: E/AndroidRuntime(873): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.newthinkjuly.addressbookapp/com.newthinkjuly.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml?

          08-12 01:28:48.115: E/AndroidRuntime(873): at com.newthinkjuly.addressbookapp.MainActivity.showAddContact(MainActivity.java:72)

          I also have working code in package form that I’m sure works. I hope that helps
          Derek

        2. I was also having that problem. To fix, make sure to include the EditContact and NewContact activities in the manifest file:

  6. I want to develope an app in android for college campus …
    I dnt hv any idea hw can I connect my server..
    Bcoz der will be dynamic update will br there in my app..
    So I hv no.idea hw cn I do that..
    CAn u pls give me.the idea hw can I do dynamic update in.my app..

  7. Hello Derek..
    Droiddraw is one app to draw the UI..
    Can we use that app to draw our UI for our android app..
    And what is the adv and dis adv of this app..??

    1. Hello, Droiddraw is in Beta and I haven’t found it to be worth covering. The main reason why is that it may or may not receive the support required to work with future versions of Android. I personally avoid using anything except those tools specifically recommended by Google. It is very common for tools like this to break and the support for them is most always very poor. This is just a personal preference and I know others who prefer to always use the newest tools. I don’t because I’ve been burned to many times. I hope that helps explain my position.

  8. I want to create AlarmManager and I have question. Will this work if I add not name or number or email, but I will put there timePicker and datePicker.

  9. Derek,

    Excellent tutorials – great job.

    As Vince mentioned earlier addressbook app: “There is an issue in callMainActivity. After u add a new contact, it does not go back to the existing MainActivity. It always creates a new MainActivity instance. If u press the Back button, it goes back to NewContact.
    I suggest getting the result of NewContact activity and then refreshing MainActivity.”.

    Could you please show how this is accomplished?

    Thank you – keep up the great work!

    1. Thank you very much πŸ™‚ It is pretty easy to refresh an activity. You just need these 2 lines of code

      finish();
      startActivity(getIntent());

      I hope that helps. I’ll try to fit that into a tutorial

  10. Instead of declaring contactId and the EditText objects in each method, does it work to just make them instance variables and assign them in onCreate()?

  11. Hi Derek,thank you so much for those tutorials,can you please help me about add blocked contact between two time slots in any day of the week ,I hope that helps.

  12. Hi Derek, first thank you for the tutorials, they’re quite helpful and you’re a very good teacher xD

    I’m stuck in this problem that stop my application everytime I click on the Contact Name. Here is the LogCat.

    09-12 19:14:46.025: E/AndroidRuntime(663): FATAL EXCEPTION: main
    09-12 19:14:46.025: E/AndroidRuntime(663): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.labpet.petapp/com.labpet.petapp.EditFicha}: java.lang.NullPointerException
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.access$600(ActivityThread.java:130)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.os.Handler.dispatchMessage(Handler.java:99)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.os.Looper.loop(Looper.java:137)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.main(ActivityThread.java:4745)
    09-12 19:14:46.025: E/AndroidRuntime(663): at java.lang.reflect.Method.invokeNative(Native Method)
    09-12 19:14:46.025: E/AndroidRuntime(663): at java.lang.reflect.Method.invoke(Method.java:511)
    09-12 19:14:46.025: E/AndroidRuntime(663): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    09-12 19:14:46.025: E/AndroidRuntime(663): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    09-12 19:14:46.025: E/AndroidRuntime(663): at dalvik.system.NativeStart.main(Native Method)
    09-12 19:14:46.025: E/AndroidRuntime(663): Caused by: java.lang.NullPointerException
    09-12 19:14:46.025: E/AndroidRuntime(663): at com.labpet.petapp.EditFicha.onCreate(EditFicha.java:41)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.Activity.performCreate(Activity.java:5008)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
    09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
    09-12 19:14:46.025: E/AndroidRuntime(663): … 11 more
    09-12 19:14:48.115: E/Trace(678): error opening trace file: No such file or directory (2)

    First I thought this were a problem on xml file, but I called the edit_ficha.xml (same as edit_contact.xml) in other function and it was totally normal. But I’m thinking that might be a problem in the EditFicha.class but i don’t know what problem could be, the class is the same as your EditContact.class :/
    If you could help I would be very grateful o/

    1. Ops, problems on the blockquote xD
      here the Logcat

      09-12 19:14:46.025: E/AndroidRuntime(663): FATAL EXCEPTION: main
      09-12 19:14:46.025: E/AndroidRuntime(663): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.labpet.petapp/com.labpet.petapp.EditFicha}: java.lang.NullPointerException
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.access$600(ActivityThread.java:130)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.os.Handler.dispatchMessage(Handler.java:99)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.os.Looper.loop(Looper.java:137)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.main(ActivityThread.java:4745)
      09-12 19:14:46.025: E/AndroidRuntime(663): at java.lang.reflect.Method.invokeNative(Native Method)
      09-12 19:14:46.025: E/AndroidRuntime(663): at java.lang.reflect.Method.invoke(Method.java:511)
      09-12 19:14:46.025: E/AndroidRuntime(663): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
      09-12 19:14:46.025: E/AndroidRuntime(663): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
      09-12 19:14:46.025: E/AndroidRuntime(663): at dalvik.system.NativeStart.main(Native Method)
      09-12 19:14:46.025: E/AndroidRuntime(663): Caused by: java.lang.NullPointerException
      09-12 19:14:46.025: E/AndroidRuntime(663): at com.labpet.petapp.EditFicha.onCreate(EditFicha.java:41)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.Activity.performCreate(Activity.java:5008)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
      09-12 19:14:46.025: E/AndroidRuntime(663): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
      09-12 19:14:46.025: E/AndroidRuntime(663): … 11 more
      09-12 19:14:48.115: E/Trace(678): error opening trace file: No such file or directory (2)

  13. Hello Derek,

    How about using startActivityForResult() rather than startactivity();
    Is it possible.
    I just wanted to know how startActivityForResult() different from startactivity();

    Umair

    1. Hi Umair,

      You use startactivity() when you simply want to start an activity and nothing else.

      Use startActivityForResult() when you start an activity just to have it do something and then end. Take a picture, get input from the user, etc.

  14. Hey Derek!
    Thank you so much for all of your videos. I find them so helpful as I start this android experience.
    I was wondering how to create a search bar to search for a contact. Thank you

    1. Hey James,

      You’re very welcome πŸ™‚ Basically you just need to put an EditText box in the app that excepts input. Then when it triggers an event handler use that input in the query. Give it a try and I’m sure you’ll get it. Everything you need has been covered.

  15. Hi derek, my apologies to bother you and whatnot but the code that you put in the .zip file actually does not work when imported into Eclipse. Are you aware of any such malfunctions?

    1. When I first import the file, it comes up with hundreds of Build Path errors, if I use the option to ‘Fix Project Automatically’ (Eclipse) I get a persistent [2013-10-29 11:22:13 – ContactsApp] Unable to resolve target ‘android-17’

  16. Hi Derek, I am having the problem of
    11-05 08:08:39.767: E/AndroidRuntime(21131): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.image/com.example.image.List_admin}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is ‘android.R.id.list’

    when I am going to show all the data of my table into ListView.
    Do you know actually what is the mistake that i did ? thx

  17. sir Derek , can you help me with this because if I run the app , the emulator will show a pop up box that says “application unfortunately stopped” and there’s an error that says

    11-05 08:08:39.767: E/AndroidRuntime(21131): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.image/com.example.image.List_admin}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is β€˜android.R.id.list’

    but in my xml file I already have this ID .

    android:id=”@+id/list”

    but still .
    it will just stop .

    can you please help me with this ?

    THANKS πŸ˜€

  18. Hello Mr. Banas , I have a problem with my address book .
    When I press the “ADD” button my address book will suddenly stopped .

    11-15 20:39:14.820: E/AndroidRuntime(1047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at dalvik.system.NativeStart.main(Native Method)
    11-15 20:39:14.820: E/AndroidRuntime(1047): Caused by: java.lang.reflect.InvocationTargetException
    11-15 20:39:14.820: E/AndroidRuntime(1047): at java.lang.reflect.Method.invokeNative(Native Method)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at java.lang.reflect.Method.invoke(Method.java:515)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.view.View$1.onClick(View.java:3809)
    11-15 20:39:14.820: E/AndroidRuntime(1047): … 11 more
    11-15 20:39:14.820: E/AndroidRuntime(1047): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.vinceport.addressbookapp/com.vinceport.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml?
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Activity.startActivityForResult(Activity.java:3423)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Activity.startActivityForResult(Activity.java:3384)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Activity.startActivity(Activity.java:3626)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at android.app.Activity.startActivity(Activity.java:3594)
    11-15 20:39:14.820: E/AndroidRuntime(1047): at com.vinceport.addressbookapp.AddressBook.showAddContact(AddressBook.java:71)
    11-15 20:39:14.820: E/AndroidRuntime(1047): … 14 more

    here’s the LogCat says .

    1. It seems from the log that

      11-15 20:39:14.820: E/AndroidRuntime(1047): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.vinceport.addressbookapp/com.vinceport.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml? –

      Manifest file is missing the declaration of the other activities created, declare those also there like
      EditContact
      NewContact

  19. Thank you for your VERY GOOD tutorials Mr. Derek and I really appreciated it :DD

    but I have some little problem …

    because when I input some records and press the SAVE button .
    my address book will suddenly STOP ..

    can you please help me with this ?

    here the errors . . .

    11-18 17:01:18.460: E/AndroidRuntime(872): at android.view.View$1.onClick(View.java:3809)
    11-18 17:01:18.460: E/AndroidRuntime(872): … 11 more
    11-18 17:01:18.460: E/AndroidRuntime(872): Caused by: java.lang.NullPointerException
    11-18 17:01:18.460: E/AndroidRuntime(872): at com.vinceport.addressbookapp.NewContact.addNewContact(NewContact.java:42)
    11-18 17:01:18.460: E/AndroidRuntime(872): … 14 more

    THANK YOU in advance Mr. Derek πŸ˜€

    1. You’re very welcome πŸ™‚ You get that error when something has the value of null when it shouldn’t. You have a typo some place in your code. Compare your class files to mine using something like diff now.com

      I hope that helps πŸ™‚

  20. Hi! I wrote on your YouTube video about posting errors. I’ve managed to fix most of the ones myself but I’m just stuck on this one. I have used the diffnow site to try and spot differences between my code and what you have supplied but now I’m struggling to see any! When I add a contact I get taken back to blank screen and errors appear on my LogCat. This doesn’t happen with your code, only with mine! The errors are as follows…

    11-30 15:08:06.555: E/SQLiteLog(7504): (1) table contacts has no column named emailAddress
    11-30 15:08:06.565: E/SQLiteDatabase(7504): Error inserting emailAddress=joe@email.com lastName=Bloggs phoneNumber=01111111111 firstName=Joe homeAddress=1 test street
    11-30 15:08:06.565: E/SQLiteDatabase(7504): android.database.sqlite.SQLiteException: table contacts has no column named emailAddress (code 1): , while compiling: INSERT INTO contacts(emailAddress,lastName,phoneNumber,firstName,homeAddress) VALUES (?,?,?,?,?)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1013)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:624)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at com.example.youtubeaddressbook.DBTools.insertContact(DBTools.java:43)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at com.example.youtubeaddressbook.NewContact.addNewContact(NewContact.java:47)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at java.lang.reflect.Method.invokeNative(Native Method)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at java.lang.reflect.Method.invoke(Method.java:511)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.view.View$1.onClick(View.java:3655)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.view.View.performClick(View.java:4162)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.view.View$PerformClick.run(View.java:17152)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.os.Handler.handleCallback(Handler.java:615)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.os.Handler.dispatchMessage(Handler.java:92)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.os.Looper.loop(Looper.java:137)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at android.app.ActivityThread.main(ActivityThread.java:4867)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at java.lang.reflect.Method.invokeNative(Native Method)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at java.lang.reflect.Method.invoke(Method.java:511)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
    11-30 15:08:06.565: E/SQLiteDatabase(7504): at dalvik.system.NativeStart.main(Native Method)

    Any tips? I’m baffled!

    1. The emailAddress wasn’t created for some reason in the database. I have the whole package here which you can compare to your code to find the typo. Compare your class files to the ones in the package using a site like diffnow.com and you’ll see the error. I hope that helps πŸ™‚

      1. I retyped emailAddress and then it somehow worked! very bizarre! But thank you πŸ™‚

        In the mean time I went through all the tutorials again and made another and with that one I have an issue with the list view..it just shows the first name twice of an added item when displayed then when you go to edit it it crashes and the errors talk about a null pointer on the onCreate?

        Sorry for all the questions, I just really want to understand whats going on with all aspects of it!

        1. The best thing to do is to get the class files in my src folder and my layout files and compare yours to mine using something like diffnow.com. It will point out the differences. I hope that helps πŸ™‚

  21. I noticed in the youtube comments that others had the same problem, the manifest file does not seem to update automatically for everyone, maybe this should be mentioned in the video? πŸ™‚

    I’m talking about the two activity tags:

  22. Another question. If I want the entries to show up like “lastName, firstName” instead, is there any “pretty” way of doing this?

    I changed the getAllContacts method to do

    contactMap.put(“lastName”, cursor.getString(2) + “, “);

    But this doesn’t feel like “best practice”.

  23. I did everything pretty nice. But when I run the application in my Emulator it shows and error and says forced to close the application, and crashes. Why is that?

      1. Your package works fine..
        Actually the Problem was the ‘list view name’..
        I missed the ‘@android:…’ format for list view..

        Thanks for your great tutorials(even though you are as fast as a metro train! πŸ™‚ )

  24. great stuff as always Derek!

    Thanks a lot for all of the fantastic tutorials ~

    I have tried testing the app on my phone as well as an AVD and get the same result.

    I click “ADD” to add a contact and it lets me walk through the fields and click “Save”. But then it does not display the contact I just added. However it adds a record because it allows me to press where the contact name should be and then gives me an error about EditContact. I figure I am getting an error on EditContact because there is no contact to edit!

    Any idea on what I may be missing?

      1. AHA! I finally got it ~

        I tried importing your code but kept getting errors (tried cleaning project everything but couldn’t get it to work) – so I just started a new project and hand created the files and copied pasted and got it to work and run properly, yay!

        So then I had to figure out what the differences were in your code and mine. And keep in mind when I say “my code”, that was just your code I copied and pasted from each page of this tutorial so when I mention these differences below, you may want to change them on your tutorial pages if that matters to you πŸ™‚

        1) DBTools.java: added @Override before oncreate and onupgrade

        2) DBTools.java: added ContactID field on the contactMap.put

        3) MainActivity.java: changed theIntent to theIndent (maybe just a typo but I changed it anyways)

        4) MainActivity.java: changed getApplication() to getApplicationContext in showAddContact (I thought this for sure was going to fix immediately but I saved and ran it and still the same result)

        — Now these next 2 changes are what really made the difference —

        5) contact_entry.xml: changed contactName textview into 2 separate ones (firstName and lastName) – when I did this, all my contact names showed up in the list, but
        still had error on edit screen

        6) edit_contact.xml: changed all editText names from lastNameEditText format to just lastName format (started displaying everything then and working properly!)

        (one last side note in NewContact.java you have phoneNumber spelled as pnoneNumber)

        Thanks again Derek, after I figured out how to compare files within eclipse it made this process much quicker for me to find what was different)

        I leave this comment with 1 question too: I see how you use the SQLite3 db to add and edit records locally but how do you set up a database that anyone in the world can edit and add records too? So for example, take this same app idea and allow multiple people all over the world add contact names to the same database?

        thanks~!

        1. Great I’m glad you fixed it and thank you for posting such a detailed comment to help others.

          To set up a shared database it is better to access a database on an outside web server. I plan on covering how to do that soon.

          1. Great, and no problem on the post…

            I can connect to DB with web development, just do not know the steps for app development..

            Going to continue taking your tutorials and look forward to that topic someday! πŸ™‚

            thanks again ~

  25. Hi Derek,
    Thanks for the cool tutorials.
    I had one problem with this address book app.
    When I create new contact, it will be saved.
    But in the list view it only shows the contact id.
    What is the problem?
    Appreciate ur help

  26. Hey Sir Derek! I like your tutorials about Android. I like them so much because you explain very well and it helped me a lot on my projects. Thank you so much. I hope you could do a tutorial about searching sqlite database. Thank you!!

  27. Hello Derek.

    First of all I just wanted to tell that you are amazing, (and I know you herd it a lot).

    Now for my issue, I have a project to make and its very similar to what you done, the difference is that I need to set the value of my contact from a spinner and a radiobutton.

    to get the values from the radio button and the spinner I used queryValuesMap.put(“productQuality”, rgQuality.getContext().toString());

    I just dont know how to set it back to their original state.

    I hope you understood me correctly, if not I would be more than happy to send you my code so you can review it.

    1. Thank you πŸ™‚ Why not take the value and record it some place and then set the spinner / radio button back to the default? I may not understand the problem. I hope that helps in some way.

      1. thank you for trying anyway πŸ™‚
        I’m kinda new in the development writing so its really hard for me to explain what I need.
        My teacher helped me with that issue, the thing is that i had a spinner that depend on another spinner so it was hard for me to turn it back to its original state, and I did saved the vales in an SQLite database.

        I wanted to ask you if you can make a guide for sliding menu using a navigation drawer.
        thank you in advance

  28. Hello Derek. I loved learning how to perform a SQLite project with Java. Unfortunatly, this thing won’t excately run and I don’t know why. When I attempt to, it takes me to the first screen. The second I hit the “ADD” button, it crashes, and its really hurting my head why. I compared my code to yours line by line and I can’t think of why this still fails.

    Its like a cruel April’s Fools joke. =(

    The debugger was giving me errors along the lines of me not defining my source properly. After messing with that, enough, I thought I fixed it, but still it refuses to work.

    Allow me to past what the debugger presently has to say.

    04-01 19:36:57.919: W/dalvikvm(2770): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
    04-01 19:36:58.006: E/AndroidRuntime(2770): FATAL EXCEPTION: main
    04-01 19:36:58.006: E/AndroidRuntime(2770): java.lang.IllegalStateException: Could not execute method of the activity
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.view.View$1.onClick(View.java:3599)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.view.View.performClick(View.java:4204)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.view.View$PerformClick.run(View.java:17355)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.os.Handler.handleCallback(Handler.java:725)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.os.Handler.dispatchMessage(Handler.java:92)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.os.Looper.loop(Looper.java:137)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.ActivityThread.main(ActivityThread.java:5041)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at java.lang.reflect.Method.invokeNative(Native Method)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at java.lang.reflect.Method.invoke(Method.java:511)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at dalvik.system.NativeStart.main(Native Method)
    04-01 19:36:58.006: E/AndroidRuntime(2770): Caused by: java.lang.reflect.InvocationTargetException
    04-01 19:36:58.006: E/AndroidRuntime(2770): at java.lang.reflect.Method.invokeNative(Native Method)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at java.lang.reflect.Method.invoke(Method.java:511)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.view.View$1.onClick(View.java:3594)
    04-01 19:36:58.006: E/AndroidRuntime(2770): … 11 more
    04-01 19:36:58.006: E/AndroidRuntime(2770): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.codecrunchcorner.addressbookapp/com.codecrunchcorner.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml?
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Activity.startActivityForResult(Activity.java:3370)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Activity.startActivityForResult(Activity.java:3331)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Activity.startActivity(Activity.java:3566)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at android.app.Activity.startActivity(Activity.java:3534)
    04-01 19:36:58.006: E/AndroidRuntime(2770): at com.codecrunchcorner.addressbookapp.MainActivity.showAddContact(MainActivity.java:79)
    04-01 19:36:58.006: E/AndroidRuntime(2770): … 14 more

    Can you help me out here? =/

    1. This is the main error Unable to find explicit activity class {com.codecrunchcorner.addressbookapp/com.codecrunchcorner.addressbookapp.NewContact}; have you declared this activity in your AndroidManifest.xml?

  29. Hi Derek!
    First of all, I’d like to thank you for providing these awesome tutorials!
    I have a problem. When I’m trying to run the app on my phone/emulator, it says “Unfortunately (app name) has stopped working”. What should I do?
    Here’s the LogCat.

    04-18 06:40:05.854: D/AndroidRuntime(932): Shutting down VM
    04-18 06:40:05.854: W/dalvikvm(932): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
    04-18 06:40:05.944: E/AndroidRuntime(932): FATAL EXCEPTION: main
    04-18 06:40:05.944: E/AndroidRuntime(932): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vitteachersdatabase/com.example.vitteachersdatabase.MainActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread.access$600(ActivityThread.java:141)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.os.Looper.loop(Looper.java:137)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread.main(ActivityThread.java:5103)
    04-18 06:40:05.944: E/AndroidRuntime(932): at java.lang.reflect.Method.invokeNative(Native Method)
    04-18 06:40:05.944: E/AndroidRuntime(932): at java.lang.reflect.Method.invoke(Method.java:525)
    04-18 06:40:05.944: E/AndroidRuntime(932): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    04-18 06:40:05.944: E/AndroidRuntime(932): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    04-18 06:40:05.944: E/AndroidRuntime(932): at dalvik.system.NativeStart.main(Native Method)
    04-18 06:40:05.944: E/AndroidRuntime(932): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    04-18 06:40:05.944: E/AndroidRuntime(932): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    04-18 06:40:05.944: E/AndroidRuntime(932): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.Activity.setContentView(Activity.java:1895)
    04-18 06:40:05.944: E/AndroidRuntime(932): at com.example.vitteachersdatabase.MainActivity.onCreate(MainActivity.java:25)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.Activity.performCreate(Activity.java:5133)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
    04-18 06:40:05.944: E/AndroidRuntime(932): … 11 more
    04-18 06:40:05.944: E/AndroidRuntime(932): Caused by: java.lang.reflect.InvocationTargetException
    04-18 06:40:05.944: E/AndroidRuntime(932): at java.lang.reflect.Constructor.constructNative(Native Method)
    04-18 06:40:05.944: E/AndroidRuntime(932): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    04-18 06:40:05.944: E/AndroidRuntime(932): … 25 more
    04-18 06:40:05.944: E/AndroidRuntime(932): Caused by: android.content.res.Resources$NotFoundException: File #FFF from drawable resource ID #0x7f05000e: .xml extension required
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.content.res.Resources.loadColorStateList(Resources.java:2255)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.widget.TextView.(TextView.java:949)
    04-18 06:40:05.944: E/AndroidRuntime(932): at android.widget.TextView.(TextView.java:607)
    04-18 06:40:05.944: E/AndroidRuntime(932): … 28 more
    04-18 06:40:11.974: I/Process(932): Sending signal. PID: 932 SIG: 9

    1. You’re very welcome πŸ™‚ Have you tried downloading the package I have on this page. If it runs then that means you have a typo some place. Use a website like diffnow to compare my files to yours. Just check the manifest, layout folder and src folder. i hope that helps

  30. Hi, your tutorials are absolutely amazing. The application runs but the list does not populate when i add a contact even if i leave all the edittexts empty it still goes back to main activity. what am i doing wrong?

  31. Hi Derek,
    Thanks a lot for these awesome tutorials. It really helped a newbie like me.
    I have 2 scenarios.
    I coded the addressbook app by following your videos.
    But when i am trying to run it ,it is quitting unexpectedly.
    The reason may be ‘fragment_main.xml’. Whenever I am trying to create a new package, It is by default creating the ‘fragment_main.xml’. I am not able to create a package without this ‘fragment_main.xml’.
    secondly, I downloaded the package from your website. But still not able to run.I followed your instruction in tutorial -14 to import. After import, It is showing lots of errors in ‘NewContact.java’ file only.Also in the console it is showing ‘Unable to resolve target ‘android 17”. Please let me know if i am doing something wrong.

      1. That workout pretty good thxs.
        “String selectQuery = “SELECT * FROM contacts WHERE lastname LIKE ‘”+ text + “%'”;”
        this query did the job. Now It is possible to filter de contactlist without using this method?

  32. Hi Derik!
    Tnx for the great tutorials it was really helpful.
    I would like to know if it is possible to create two database in the same android application, or create two tables (same database) in the same android app.
    Can u please provide me with some links to tutorials covering that subject
    Tnx a lot !

  33. Hi Derek!

    I’m new to android programming and I was wondering why when I imported your whole project to my eclipse the R.java is missing in the generated package?

    Great tutorials btw. thanks.

    Jed

  34. Hi MASTER DEREK.

    I’m fiddling with my first app and another question arose:
    suppose I’d like to have several phones/email per contact-
    I guess I create another contact-phone TABLE (with contactId is the foreign Key)
    how should I deal with those added table regarding insertion-
    updating-deleting data.
    Thank you so much man!

    1. Hi,

      I’d go this route for designing that in the database, but you could also just list each possible phone number in one table

      Contact (
      ContactId
      )

      ContactPhone (
      ContactId references Contact(ContactId)
      PhoneType
      PhoneNumber
      )

  35. First, thanks for this series.
    Second I am having an issue with the listView in activity_main.
    Everything works but nothing is displayed. I can tap on the row and it goes to the edit screen (after addeng records). I am not sure if the listAddaptor in not filling in the list (my guess) or the list is white for both text and background.
    I suspect all of this is a result of some bug/quirk with Androud Studio.
    Thoughts?
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *