Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7930447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:25:40+00:00 2026-06-03T20:25:40+00:00

im developing a map application in android that search for places in the database

  • 0

im developing a map application in android that search for places in the database based on the user’s search input.
im trying to query the sqlite database using a field which will search in the database and return the latitude of the places which all in the database.The field is not a primary key below are the codes.
Please i need Help.
the database class to create and access database.

public class Places {
private Context context;
private DbHelper dataHelper;
private SQLiteDatabase database;

//columns for places table
public static final String ROW_ID="_id";
public static final String P_NAME="placename";
public static final String G_NAME="genericname";
public static final String LONGITUDE="longitude";
public static final String LATITUDE="latitude";
public static final String CONTACT="contactnumbers";



private static final String DB_NAME="MAP.db";
private static final String DB_TABLE_PLACES="places";
private static final String DB_TABLE_EXAMS="exam";
private static final String DB_TABLE_SMS="message";
private static final int DB_VERSION= 1;

//constructor for Places.java

 public Places(Context c){
     this.context = c;
 }

//database helper class

private static class DbHelper extends SQLiteOpenHelper  {


 //constructor for DbHelper inner class

public DbHelper(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    //creating table PLACES
    db.execSQL("CREATE TABLE "+DB_TABLE_PLACES+"("+ROW_ID+" PRIMARY KEY, " +
            ""+P_NAME+" TEXT NOT NULL, " +
            ""+G_NAME+" TEXT NOT NULL, " +
            ""+LONGITUDE+" TEXT NOT NULL, " +
            ""+LATITUDE+" TEXT NOT NULL, " +
            ""+CONTACT+" TEXT );");



    @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS "+DB_TABLE_PLACES);
    db.execSQL("DROP TABLE IF EXISTS "+DB_TABLE_EXAMS);
    db.execSQL("DROP TABLE IF EXISTS "+DB_TABLE_SMS);

    onCreate(db);
}

}

  public Places openDatabase() throws SQLiteException{
   dataHelper = new DbHelper(context);
   database= dataHelper.getWritableDatabase();
return this;

}

  public void closeDatabase(){
dataHelper.close();
database.close();

}

@SuppressWarnings("null")
 public List<String> getPlaceLatitude(String string) {
// TODO Auto-generated method stub

List<String> latitudes = null;
String[] columns= new String[]{ROW_ID,P_NAME,LATITUDE,LONGITUDE,G_NAME,CONTACT};

Cursor c = database.query(DB_TABLE_PLACES, columns,G_NAME+" = "+string, null, null, null, null);

int iLatitude = c.getColumnIndex(LATITUDE);
if (c !=null){
for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
    latitudes.add(c.getString(iLatitude));
}
}
return latitudes;}

method that triggers action to query database.

public void searchDbAndOpenIntent(String search){
try{
        Places placeDb = new Places(this);
        placeDb.openDatabase();
        List<String> longitude1= placeDb.getPlaceLongitude(search);
                List<String> latitude1=placeDb.getPlaceLatitude(search);
        placeDb.closeDatabase();
}
                  catch (Exception e) {
            // TODO:handle exception                                    Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
        }
}




public void searchDbAndOpenIntent(String search){
try{
        Places placeDb = new Places(this);
        placeDb.openDatabase();
        List<String> longitude1= placeDb.getPlaceLongitude(search);
                List<String> latitude1=placeDb.getPlaceLatitude(search);
        placeDb.closeDatabase();



        }
                  catch (Exception e) {
            // TODO: handle exception


            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
}

please i want to return the latitude based on the the generic name of the places,but when i try to query the generic_name column it returns java.lang.NullPointerexception .below it the log cat i get when the button that query the database when pressed

       05-14 20:52:37.202: D/ddm-heap(243): Got feature list request
       05-14 20:52:41.123: E/ActivityThread(243): Failed to find provider info for       com.google.settings
       05-14 20:52:41.132: E/ActivityThread(243): Failed to find provider info for   com.google.settings
       05-14 20:52:41.172: E/ActivityThread(243): Failed to find provider info for com.google.settings
       05-14 20:52:41.562: D/dalvikvm(243): GC freed 2007 objects / 134424 bytes in 125ms
       05-14 20:52:41.802: D/LocationManager(243): Constructor: service =   android.location.ILocationManager$Stub$Proxy@44e8c078
       05-14 20:52:42.012: I/MapActivity(243): Handling network change  notification:CONNECTED
       05-14 20:52:42.012: E/MapActivity(243): Couldn't get connection factory client
       05-14 20:52:42.453: D/dalvikvm(243): GC freed 4934 objects / 288736 bytes in 136ms
       05-14 20:52:48.852: D/dalvikvm(243): GC freed 10599 objects / 817800 bytes in  137ms
       05-14 20:53:56.712: W/KeyCharacterMap(243): No keyboard for id 0
       05-14 20:53:56.723: W/KeyCharacterMap(243): Using default keymap: /system /usr/keychars/qwerty.kcm.bin
       05-14 20:53:59.712: D/LocationManager(243): removeUpdates: listener =  my.project.success.KnustP2PActivity@44e93c70
       05-14 20:54:11.812: D/dalvikvm(243): GC freed 5940 objects / 725376 bytes in 98ms
       05-14 20:54:11.812: I/dalvikvm(243): Uncaught exception thrown by finalizer (will be discarded):
       05-14 20:54:11.812: I/dalvikvm(243): Ljava/lang/IllegalStateException;:  Finalizing cursor android.database.sqlite.SQLiteCursor@44f31670 on places that has not  been deactivated or closed
       05-14 20:54:11.812: I/dalvikvm(243):     at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
       05-14 20:54:11.822: I/dalvikvm(243):     at dalvik.system.NativeStart.run(Native Method)
       05-14 20:54:11.872: E/Database(243): Leak found
       05-14 20:54:11.872: E/Database(243): java.lang.IllegalStateException: /data/data/my.project.success/databases/MAP.db SQLiteDatabase created and never closed
       05-14 20:54:11.872: E/Database(243):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1694)
       05-14 20:54:11.872: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)
       05-14 20:54:11.872: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)
       05-14 20:54:11.872: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)
       05-14 20:54:11.872: E/Database(243):     at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
       05-14 20:54:11.872: E/Database(243):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
       05-14 20:54:11.872: E/Database(243):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
       05-14 20:54:11.872: E/Database(243):     at my.project.success.Places.openDatabase(Places.java:201)
       05-14 20:54:11.872: E/Database(243):     at my.project.success.SearchActivity.searchDbAndOpenIntent(SearchActivity.java:217)
       05-14 20:54:11.872: E/Database(243):     at my.project.success.SearchActivity.onClick(SearchActivity.java:151)
       05-14 20:54:11.872: E/Database(243):     at android.view.View.performClick(View.java:2364)
       05-14 20:54:11.872: E/Database(243):     at android.view.View.onTouchEvent(View.java:4179)
       05-14 20:54:11.872: E/Database(243):     at android.widget.TextView.onTouchEvent(TextView.java:6540)
       05-14 20:54:11.872: E/Database(243):     at android.view.View.dispatchTouchEvent(View.java:3709)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:11.872: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
       05-14 20:54:11.872: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
       05-14 20:54:11.872: E/Database(243):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
       05-14 20:54:11.872: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
       05-14 20:54:11.872: E/Database(243):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
       05-14 20:54:11.872: E/Database(243):     at android.os.Handler.dispatchMessage(Handler.java:99)
       05-14 20:54:11.872: E/Database(243):     at android.os.Looper.loop(Looper.java:123)
       05-14 20:54:11.872: E/Database(243):     at     android.app.ActivityThread.main(ActivityThread.java:4363)
       05-14 20:54:11.872: E/Database(243):     at java.lang.reflect.Method.invokeNative(Native Method)
       05-14 20:54:11.872: E/Database(243):     at java.lang.reflect.Method.invoke(Method.java:521)
       05-14 20:54:11.872: E/Database(243):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
       05-14 20:54:11.872: E/Database(243):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
       05-14 20:54:11.872: E/Database(243):     at dalvik.system.NativeStart.main(Native Method)
       05-14 20:54:12.014: I/dalvikvm(243): Uncaught exception thrown by finalizer (will be discarded):
       05-14 20:54:12.022: I/dalvikvm(243): Ljava/lang/IllegalStateException;: Finalizing cursor  android.database.sqlite.SQLiteCursor@44f2f0b0 on places that has not been deactivated or closed
       05-14 20:54:12.022: I/dalvikvm(243):     at android.database.sqlite.SQLiteCursor.finalize(SQLiteCursor.java:596)
       05-14 20:54:12.032: I/dalvikvm(243):     at dalvik.system.NativeStart.run(Native Method)
       05-14 20:54:12.152: E/Database(243): Leak found
       05-14 20:54:12.152: E/Database(243): java.lang.IllegalStateException: /data/data/my.project.success/databases/MAP.db SQLiteDatabase created and never closed
       05-14 20:54:12.152: E/Database(243):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1694)
       05-14 20:54:12.152: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)
       05-14 20:54:12.152: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)
       05-14 20:54:12.152: E/Database(243):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)
       05-14 20:54:12.152: E/Database(243):     at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
       05-14 20:54:12.152: E/Database(243):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
       05-14 20:54:12.152: E/Database(243):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
       05-14 20:54:12.152: E/Database(243):     at my.project.success.Places.openDatabase(Places.java:201)
       05-14 20:54:12.152: E/Database(243):     at my.project.success.SearchActivity.searchDbAndOpenIntent(SearchActivity.java:217)
       05-14 20:54:12.152: E/Database(243):     at my.project.success.SearchActivity.onClick(SearchActivity.java:79)
       05-14 20:54:12.152: E/Database(243):     at android.view.View.performClick(View.java:2364)
       05-14 20:54:12.152: E/Database(243):     at android.view.View.onTouchEvent(View.java:4179)
       05-14 20:54:12.152: E/Database(243):     at android.widget.TextView.onTouchEvent(TextView.java:6540)
       05-14 20:54:12.152: E/Database(243):     at android.view.View.dispatchTouchEvent(View.java:3709)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
       05-14 20:54:12.152: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
       05-14 20:54:12.152: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
       05-14 20:54:12.152: E/Database(243):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
       05-14 20:54:12.152: E/Database(243):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
       05-14 20:54:12.152: E/Database(243):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
       05-14 20:54:12.152: E/Database(243):     at android.os.Handler.dispatchMessage(Handler.java:99)
       05-14 20:54:12.152: E/Database(243):     at android.os.Looper.loop(Looper.java:123)
       05-14 20:54:12.152: E/Database(243):     at android.app.ActivityThread.main(ActivityThread.java:4363)
       05-14 20:54:12.152: E/Database(243):     at java.lang.reflect.Method.invokeNative(Native Method)
       05-14 20:54:12.152: E/Database(243):     at java.lang.reflect.Method.invoke(Method.java:521)
       05-14 20:54:12.152: E/Database(243):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
       05-14 20:54:12.152: E/Database(243):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
       05-14 20:54:12.152: E/Database(243):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:25:41+00:00Added an answer on June 3, 2026 at 8:25 pm

    You need to enclose the string variable in single quotes in your query.

    It should look like this:

    G_NAME+" = '" + string + "'"
    

    EDIT

    This is incorrect, as you are trying to access the cursor without moving to the first record first:

    int iLatitude = c.getColumnIndex(LATITUDE);
    if (c !=null){
    for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
        latitudes.add(c.getString(iLatitude));
    }
    

    Try this:

    c.moveToFirst();
    int iLatitude = c.getColumnIndex(LATITUDE);
    if (c !=null){
        while(c.isAfterLast == false){
            latitudes.add(c.getString(iLatitude));
            c.moveToNext();
        }
    }
    

    This also changes your loop, mostly in the interest of readability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a map application in Android. I'm using Google maps API to show
I'm using Android 2.3.3 and Google APIs for developing a Map application. The problem
i am trying to run google map tutorial using following link http://mobiforge.com/developing/story/using-google-maps-android followed all
I am developing an mobile application that search the user's location via GPS and
I am currently developing an android application uses Google map API. I am wondering
i am developing android applicaiton disply user overlays on map.user values getting from webservices
Developing iphone application using makkit framework. I have got the map view integrated in
I'm developing an application on Android with the use of Google Map. I've successfully
I am developing sample application that uses Google Map API. I have generated Google
I am developing a j2me map based application. Screen is divided into a grid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.