1

here is the logcat. what seems to be the error here?

03-07 03:11:55.841: D/dalvikvm(292): GC_EXTERNAL_ALLOC freed 4085 objects / 243720 bytes in 190ms
03-07 03:11:56.221: D/dalvikvm(292): GC_EXTERNAL_ALLOC freed 303 objects / 16040 bytes in 85ms
03-07 03:12:06.990: W/KeyCharacterMap(292): No keyboard for id 0
03-07 03:12:06.990: W/KeyCharacterMap(292): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
03-07 03:12:07.190: E/Cursor(292): Invalid statement in fillWindow()

1st activity which gets the data from my sqliteadapter

  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.search);
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


  mySQLiteAdapter = new SQLiteAdapter(this);
  mySQLiteAdapter.openToRead();

  Cursor cursor = mySQLiteAdapter.queueAll();
  startManagingCursor(cursor);

  String[] from = new String[]{SQLiteAdapter.KEY_FOODNAME,SQLiteAdapter.KEY_CALORIES};
  int[] to = new int[]{R.id.tv1, R.id.tv2};

  SimpleCursorAdapter cursorAdapter =
   new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);

  listContent1.setAdapter(cursorAdapter);
  listContent1.setOnItemClickListener(listContentOnItemClickListener); 
  mySQLiteAdapter.close();
   private ListView.OnItemClickListener listContentOnItemClickListener = new ListView.OnItemClickListener(){
 public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {

  Cursor cursor = (Cursor) parent.getItemAtPosition(position);

  String item_content1 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_FOODNAME));
  String item_content2 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_CALORIES));
  arlene = arlene + Integer.parseInt(item_content2);
  String item = String.valueOf(" Food Name: " + item_content1 ) + "\n" +
          " Calories: " +  item_content2;

   Toast.makeText(Search.this, item, Toast.LENGTH_LONG).show();      

   food.setText(item_content1);
   calories.setText(String.valueOf(arlene));


   Intent myIntent = new Intent(Search.this, Foodlog.class);
   Bundle bundle = new Bundle();
   bundle.putString("SQLITEDATA1", food.getText().toString()); 
   bundle.putString("SQLITEDATA2", calories.getText().toString()); 
   myIntent.putExtras(bundle);
   startActivity(myIntent); 



   SavePreferences("calories", calories.getText().toString());
   LoadPreferences();

2nd activity which gets the data passed

   Bundle bundle = getIntent().getExtras();  
   if( bundle != null){
   String food = bundle.getString("SQLITEDATA1");
   String calories = bundle.getString("SQLITEDATA2");

   String[] values = new String[] { food, calories }; //That you got from your intent bundle
   LVAdapter adapter = new LVAdapter(this, R.layout.foodlist, values);
   setListAdapter(adapter);

and when i pressed back, it will clear all the listview data on my 1st activity

michelle.mo
  • 53
  • 2
  • 9
  • can you please share your code – MDMalik Mar 06 '13 at 19:25
  • It is impossible to tell without seeing the relevant code and if there are any more LogCat errors. But this may help: [what does Invalid statement in fillWindow() in android cursor mean?](http://stackoverflow.com/questions/4195089/what-does-invalid-statement-in-fillwindow-in-android-cursor-mean) – Sam Mar 06 '13 at 19:28
  • posted it please help me – michelle.mo Mar 06 '13 at 19:35
  • When does this error occur? Use `@Sam` to reply directly to a user otherwise we might never know you replied. – Sam Mar 06 '13 at 19:43
  • oh alright @Sam when i click an item on the listview, it will pass that item on the next listview but when i back pressed, when it returns to the 1st listview. all the data there is gone or erased and that appears in my logcat. – michelle.mo Mar 06 '13 at 19:46
  • Please post your code for `SQLiteAdapter#close()`. – Sam Mar 06 '13 at 20:10
  • @Sam is this the right code you ask for? im now really sure? public void close() { sqLiteHelper.close(); } – michelle.mo Mar 06 '13 at 20:23
  • Yes that was what wanted to see, but it isn't the problem... Please click "[edit]" and add `queueAll()` to your quesiton. – Sam Mar 06 '13 at 20:46
  • try to close cursor into your code and also database after use it, as given in the link by Sam. and you have used two cursor with same name"cursor" try to rename your inner cursor name and close it too. – Maulik Mar 07 '13 at 13:52
  • public Cursor queueAll(){ String[] columns = new String[]{KEY_ID, KEY_FOODNAME, KEY_CALORIES}; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null); return cursor; } my queueAll – michelle.mo Mar 07 '13 at 16:58
  • @Sam i posted my queueall – michelle.mo Mar 07 '13 at 17:29

1 Answers1

1

In onCreate remove

mySQLiteAdapter.close();  

move it to onDestroy

@override
protected void onDestroy()
{
    mySQLiteAdapter.close();  
}
Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54