• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating Database and Tables

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain me where android store sqLite database....
I have created database and tables on the click event of a Button.... so I just need to verify whether the database and table have been created or not....


I am trying to create database and table on the click event of
button... when I am clicking on the button for creating database and
table... it is saying that process com.example.hw3 has stopped
unexpectedly...please try again... Below is the code... what wrong I
am doing....??
Somebody Please help me....



 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

. so I just need to verify whether the database and table have been created or not....


Database is created inside your application and you can browse to it using adb shell. It must be there in /data/data/your_app_name folder

As regards exception you are getting it would help if you post exception logs from logcat.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying back...
Actually I am new to Android and SQLite..... so if you can give the command and where these commands I have to type then I can check whether the tables have been created or not...
And also give some example of logcat and how to use it.... so that I can post the exception over here....
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raihan Jamal wrote:Thanks for replying back...
Actually I am new to Android and SQLite..... so if you can give the command and where these commands I have to type then I can check whether the tables have been created or not...
And also give some example of logcat and how to use it.... so that I can post the exception over here....



How to see the database file and logs:
If you are using Eclipse:
switch to DDMS perspective - > File Browser -> Browse to data/data/your_package_name folder. There you would see your database.
Similarly to see the logs, switch to Logcat view.

Else wise:

From the SDK_installation/tools folder, type adb shell. This will give you the shell prompt.
cd to data/data/your_package_name/

to get the logs type adb logcat from the SDK_installation/tools context.

Also, read Android FAQs(see my signature for a link) some of the very basic questions are listed there.

 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying...
I am having one more problem now...
I am using this below java file to create a database and table on the click event of Create DB Button( till here it is working fine) and then below this Create DB button, there is one more button named Send Button... and on the click event of Send Button I am opening another activity which contains a edit text and a button called Insert(this is also working fine for me) and on the click event of this Insert Button... I have to insert the value that we are typing into edit text box into the table that we have created previously.... but I am not able to figure it out why it is not inserting into table that we have created previously... what wrong I am doing please let me know.... Below are the codes....
-----------------
This Code contains Create DB Button and Send Button and click event also that are creating tables and database




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

This is the Code for an Activity that contain edit text and Insert Button....I think something wrong I am doing in the try block of this code..... Please help


 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You are not passing actual values stored in your variables; should you be using str,pp inline in your query?
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Monu,
Thanks a lot for replying.... I have figured it out the above problem... Can you just tell me what is wrong with this below code...
I am trying to get the location of phone as latitude and longitude by using location manager but everytime I do this.... Force Close message appears... I have also added permission in android.manifest file...
what wrong I am doing here...?? DO reply..
Thanks..

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an app is forcibly closed then there should be a message in the logcat output.
My guess would be that "loc" is null because there is no known last location.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying... so what should I do in this case... Should I change latitude and longitude value in the emulator control or something else..please guide..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See "Providing Mock Location Data" in http://developer.android.com/guide/topics/location/index.html

Next time please mention right away if you're using the emulator; that's crucial information.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey... SOrry for that....
I am not able to use geo.... I don't know why... and I was usuing by this way also.... (http://www.devx.com/wireless/Article/39239/1763?supportItem=6) and I also click on send button to send the latitude and longitude value but still I got force close message...

this is my logcat output.. and this is the error I am having when I try to extract the latitude and longitude value
04-21 17:22:19.550: ERROR/AndroidRuntime(258): java.lang.NullPointerException


Do reply.. what to do?

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which object is null - is it "loc"? If so, have you tried supplying mock data like the link I posted suggested? Also, have you tried running this code on an actual device that has a GPS that has locked in on a position? Have you tried using the network location provider?
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think so Loc is pointing to be null that's why it giving me error on double lat = loc.getLatitude(); by logcat ouput...
Actually My actual device is not working properly... so that's why I am working on emulator ryt now...
yeah I have provided the latitude and longitude value like this (http://www.devx.com/wireless/Article/39239/1763?supportItem=6) and also I have click on send button to send the latitude and longitude values...
Have you tried using the network location provider?
what does this means??
Meaning using cellid and locationid of phone??
Do reply... What wrong I am doing...?
I have tried all the things that I know as I am new to android and Sqlite....

Thanks in advance...
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code lists all providers (most likely two: gps and network). Even the emulator should have the network provider. If you provide a LocationListener then your app will be notified once a location is established. If you search the net you'll find articles and examples of this.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick reply... Now I see some entry in to table ... but in latitude filed I am getting zero always
What I am trying now just for checking that latitude value I am getting is right or not.... so I am just inserting this latitude value in to the table... which has a datatype
like this (ph_location REAL) so now when I see in to the table, this latitude field has 0 entry always irrespective of changing the location...

I am changing the location by this way...
C:\>telnet localhost 5554
Android Console: type 'help' for a list of commands
OK
geo fix -82.411629 28.054553
OK

this is the code.... it is like that we have to use location manager in the onCreate method.... as i am using location manager on the click event of button...

Do reply
thanks...




 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is like that we have to use location manager in the onCreate method


It doesn't work like that. If the device/emulator hasn't fixed a position yet then you'll get a null value. I think there are ways of running code at device startup time - if that registers a LocationListener and stores the results it gets, then your app code may have a location available upon startup.

Easier to implement is probably to register a LocationListener in the onCreate method of your app, and then to wait until the app is notified about a location. Assuming that the GPS hasn't just been turned on that shouldn't take long.
 
Raihan Jamal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your help... I have solved that problem.... I have learnt a lot by our conversations....
Really Thanks....
I have inserted latitude and longitude values into the database... now I have to find the nearest location from the current location....
I am confuse how should I proceed... Just like there is a concept of Oracle Spatial Database and in it we can use SDO_GEOMETRY for this thing .... so In android and sqlite how we can solve this problem...
Do reply...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic