0

I am a bit confused on how to retrieve the title and snippet that i have saved in my SQLite database. I saved the title and snippet and can see it in my database, but am not entirely sure on how to retrieve the information needed.

So this is how i save my title and snippet:

contentValues.put(LocationsDB.FIELD_TITLE, title.getText().toString());
contentValues.put(LocationsDB.FIELD_SNIPPET, snippet.getText().toString());

So with this i can see (with accessing the database) that the title and snippet is saved. Now my question is how can i retrieve that information?

I can retieve the latlng values as well as the zoom level, but don't know how to get the title and snippet:

loading the latlng values and zoom level:

Marker marker;

......

@Override
public void onLoadFinished(Loader<Cursor> arg0, Cursor arg1) {
    int locationCount = 0;
    double lat=0;
    double lng=0;
    float zoom=0;
    float title = 0; \\Don't know if this part is correct..with warning "The value of the local variable title is not used" 
    float snippet = 0; \\Don't know if this part is correct ..with warning "The value of the local variable title is not used"
    locationCount = arg1.getCount();
    arg1.moveToFirst();

    for(int i=0;i<locationCount;i++){

 lat = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LAT));
 lng = arg1.getDouble(arg1.getColumnIndex(LocationsDB.FIELD_LNG));
 zoom = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_ZOOM));
 title = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_TITLE));
 snippet = arg1.getFloat(arg1.getColumnIndex(LocationsDB.FIELD_SNIPPET));
 point = new LatLng(lat, lng);
 drawMarker(point); 
 arg1.moveToNext();
    }
    if(locationCount>0){
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat,lng)));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(zoom));
        TextView titleText = (TextView) v.findViewById(R.id.TitleId);
        titleText.setText(marker.getTitle());
        TextView snippetText = (TextView) v.findViewById(R.id.SnippetId);
        snippetText.setText(marker.getSnippet());

Doing this the app just then crashes? Am really hoping someone could help me and explain what i am doing wrong

EDIT

The Stacktrace:

01-07 18:45:07.788: E/AndroidRuntime(17933): FATAL EXCEPTION: main
01-07 18:45:07.788: E/AndroidRuntime(17933): Process: com.example.MapTest, PID: 17933
01-07 18:45:07.788: E/AndroidRuntime(17933): java.lang.NullPointerException
01-07 18:45:07.788: E/AndroidRuntime(17933):    at com.example.MapTest.MainMap.onLoadFinished(MainMap.java:357)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at com.example.MapTest.MainMap.onLoadFinished(MainMap.java:1)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:427)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:395)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.Loader.deliverResult(Loader.java:104)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:73)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:35)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:223)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.AsyncTaskLoader$LoadTask.onPostExecute(AsyncTaskLoader.java:61)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:461)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.ModernAsyncTask.access$500(ModernAsyncTask.java:47)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:474)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.os.Handler.dispatchMessage(Handler.java:102)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.os.Looper.loop(Looper.java:136)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at android.app.ActivityThread.main(ActivityThread.java:5586)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at java.lang.reflect.Method.invokeNative(Native Method)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at java.lang.reflect.Method.invoke(Method.java:515)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
01-07 18:45:07.788: E/AndroidRuntime(17933):    at dalvik.system.NativeStart.main(Native Method)

And the line (357):

titleText.setText(marker.getTitle());
wemapps
  • 111
  • 8

0 Answers0