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 3494624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:01:40+00:00 2026-05-18T12:01:40+00:00

I newbie in Android and before ask question here i was googling, but on

  • 0

I newbie in Android and before ask question here i was googling, but on this question i can’t find answer. (also this stackoverflow.com/questions/4195089 don’t have answer).

In my test app on emulator i have error ERROR/Cursor(1512): Invalid statement in fillWindow() on LogCat when i press back button on second activity.
11-23 19:06:05.050: DEBUG/TestDB/Debug/MainActivity(1512): onCreate
11-23 19:06:06.820: DEBUG/TestDB/Debug/MainActivity(1512): openDataBase
11-23 19:06:07.240: DEBUG/TestDB/Debug/MainActivity(1512): String[] from
11-23 19:06:07.270: DEBUG/TestDB/Debug/MainActivity(1512): SimpleCursorAdapter
11-23 19:06:07.500: DEBUG/TestDB/Debug/MainActivity(1512): myDbHelper.close
11-23 19:06:07.520: DEBUG/TestDB/Debug/MainActivity(1512): onStart
11-23 19:06:07.551: DEBUG/TestDB/Debug/MainActivity(1512): onResume
11-23 19:06:09.040: INFO/ActivityManager(587): Displayed activity ru.olegi/.MainActivity: 7962 ms
11-23 19:06:11.850: INFO/ActivityManager(587): Starting activity: Intent { comp={ru.olegi/ru.olegi.AnotherActivity} }
11-23 19:06:12.100: DEBUG/TestDB/Debug/AnotherActivity(1512): onCreate
11-23 19:06:12.970: INFO/ActivityManager(587): Displayed activity ru.olegi/.AnotherActivity: 1100 ms
11-23 19:06:14.550: ERROR/Cursor(1512): Invalid statement in fillWindow()
11-23 19:06:14.590: DEBUG/TestDB/Debug/MainActivity(1512): onStart
11-23 19:06:14.600: DEBUG/TestDB/Debug/MainActivity(1512): onResume

All code stored in onCreate. So when i press back, ListView is empty. For fix this i move code to onStart. Here is log for this and again have Invalid statement in fillWindow()

11-23 19:26:06.280: DEBUG/TestDB/Debug/MainActivity(6597): onCreate
11-23 19:26:06.462: DEBUG/TestDB/Debug/MainActivity(6597): onStart
11-23 19:26:06.700: DEBUG/TestDB/Debug/MainActivity(6597): openDataBase
11-23 19:26:06.740: DEBUG/TestDB/Debug/MainActivity(6597): String[] from
11-23 19:26:06.750: DEBUG/TestDB/Debug/MainActivity(6597): SimpleCursorAdapter
11-23 19:26:06.981: DEBUG/TestDB/Debug/MainActivity(6597): myDbHelper.close
11-23 19:26:07.010: DEBUG/TestDB/Debug/MainActivity(6597): onResume
11-23 19:26:08.030: INFO/ActivityManager(587): Displayed activity ru.olegi/.MainActivity: 3876 ms
11-23 19:26:15.419: INFO/ActivityManager(587): Starting activity: Intent { comp={ru.olegi/ru.olegi.AnotherActivity} }
11-23 19:26:15.770: DEBUG/TestDB/Debug/AnotherActivity(6597): onCreate
11-23 19:26:16.440: INFO/ActivityManager(587): Displayed activity ru.olegi/.AnotherActivity: 1001 ms
11-23 19:26:17.860: ERROR/Cursor(6597): Invalid statement in fillWindow()
11-23 19:26:17.870: DEBUG/TestDB/Debug/MainActivity(6597): onStart
11-23 19:26:18.260: DEBUG/TestDB/Debug/MainActivity(6597): openDataBase
11-23 19:26:18.290: DEBUG/TestDB/Debug/MainActivity(6597): String[] from
11-23 19:26:18.310: DEBUG/TestDB/Debug/MainActivity(6597): SimpleCursorAdapter
11-23 19:26:18.670: DEBUG/TestDB/Debug/MainActivity(6597): myDbHelper.close
11-23 19:26:18.700: DEBUG/TestDB/Debug/MainActivity(6597): onResume

This code

package ru.olegi;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    private DatabaseHelper myDbHelper;  
    private ListView lv1;   

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("TestDB/Debug/MainActivity", "onCreate");          

        setContentView(R.layout.main);        

    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("TestDB/Debug/MainActivity", "onStart");

        // DATABASE OPEN - START
        DatabaseHelper myDbHelper = new DatabaseHelper(this);
        myDbHelper = new DatabaseHelper(this);

        try {
            myDbHelper.createDataBase();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }          

        try {
            myDbHelper.openDataBase();
        }catch(SQLException sqle){
            throw sqle;
        }        

        Log.d("TestDB/Debug/MainActivity", "openDataBase");        

        // DATABASE OPEN - END

        Cursor c = myDbHelper.fetchAllFoodname();
        startManagingCursor(c);                       

        lv1 = (ListView) findViewById(R.id.ListView01);

        String[] from = new String[] { DatabaseHelper.KEY_NAME };
        int[] to = new int[] { android.R.id.text1};

        Log.d("TestDB/Debug/MainActivity", "String[] from");

        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, c, from, to);

        Log.d("TestDB/Debug/MainActivity", "SimpleCursorAdapter");

        lv1.setAdapter(notes);

        lv1.setOnItemClickListener(new OnItemClickListener() {      
            //@Override     
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {

                Intent intent = new Intent();

                //getApplicationContext()
                intent.setClass(MainActivity.this, AnotherActivity.class);

                //intent.putExtra(AnotherActivity.EXT_ID, id);              

                startActivity(intent);
                //finish(); 
            }   
         });   

        // DATABASE CLOSE - START       

        myDbHelper.close();
        Log.d("TestDB/Debug/MainActivity", "myDbHelper.close");

        // DATABASE CLOSE - END         
    }    

    @Override
    public void onResume(){
        super.onResume();
        Log.d("TestDB/Debug/MainActivity", "onResume"); 
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d("TestDB/Debug/MainActivity", "onDestroy");        
    }        
}

Here groups.google.com/group/android-developers/browse_thread/thread/8bec793c626fb405 i read, for fix fillwindow() error need

Short answer; Your database object
(db) is in the wrong scope. Longer
answer; By declaring db in the method
you’re saying to the JVM that when
the method finishes your database
connection (db) is no longer useful.
What you should do is declare db at
the class level instead of the method
level, create it in onCreate, and
close it in onDestroy.

Ok, i move sections // DATABASE OPEN – START and // DATABASE CLOSE – START to onCreate and to onDestory. And now i have exception on start

11-23 19:35:39.310: DEBUG/TestDB/Debug/MainActivity(8975): onCreate
11-23 19:35:40.050: DEBUG/TestDB/Debug/MainActivity(8975): openDataBase
11-23 19:35:40.050: DEBUG/TestDB/Debug/MainActivity(8975): onStart
11-23 19:35:40.090: DEBUG/AndroidRuntime(8975): Shutting down VM
11-23 19:35:40.100: WARN/dalvikvm(8975): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
11-23 19:35:40.120: ERROR/AndroidRuntime(8975): Uncaught handler: thread main exiting due to uncaught exception
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): java.lang.RuntimeException: Unable to start activity ComponentInfo{ru.olegi/ru.olegi.MainActivity}: java.lang.NullPointerException
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.os.Looper.loop(Looper.java:123)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread.main(ActivityThread.java:3948)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at java.lang.reflect.Method.invoke(Method.java:521)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at dalvik.system.NativeStart.main(Native Method)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): Caused by: java.lang.NullPointerException
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at ru.olegi.MainActivity.onStart(MainActivity.java:59)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1205)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.Activity.performStart(Activity.java:3490)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2240)
11-23 19:35:40.300: ERROR/AndroidRuntime(8975): … 11 more

Here is code with moved db-sections:

package ru.olegi;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.SQLException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    private DatabaseHelper myDbHelper;  
    private ListView lv1;   

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("TestDB/Debug/MainActivity", "onCreate");          

        setContentView(R.layout.main);

        // DATABASE OPEN - START
        DatabaseHelper myDbHelper = new DatabaseHelper(this);
        myDbHelper = new DatabaseHelper(this);

        try {
            myDbHelper.createDataBase();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }          

        try {
            myDbHelper.openDataBase();
        }catch(SQLException sqle){
            throw sqle;
        }        

        Log.d("TestDB/Debug/MainActivity", "openDataBase");        

        // DATABASE OPEN - END


    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d("TestDB/Debug/MainActivity", "onStart");

        Cursor c = myDbHelper.fetchAllFoodname();
        startManagingCursor(c);                       

        lv1 = (ListView) findViewById(R.id.ListView01);

        String[] from = new String[] { DatabaseHelper.KEY_NAME };
        int[] to = new int[] { android.R.id.text1};

        Log.d("TestDB/Debug/MainActivity", "String[] from");

        SimpleCursorAdapter notes =
            new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, c, from, to);

        Log.d("TestDB/Debug/MainActivity", "SimpleCursorAdapter");

        lv1.setAdapter(notes);

        lv1.setOnItemClickListener(new OnItemClickListener() {      
            //@Override     
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {

                Intent intent = new Intent();

                //getApplicationContext()
                intent.setClass(MainActivity.this, AnotherActivity.class);

                //intent.putExtra(AnotherActivity.EXT_ID, id);              

                startActivity(intent);
                //finish(); 
            }   
         });   

    }    

    @Override
    public void onResume(){
        super.onResume();
        Log.d("TestDB/Debug/MainActivity", "onResume"); 
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d("TestDB/Debug/MainActivity", "onDestroy");

        // DATABASE CLOSE - START       

        myDbHelper.close();
        Log.d("TestDB/Debug/MainActivity", "myDbHelper.close");

        // DATABASE CLOSE - END     
    }        
}

Please, help fix Invalid statement in fillWindow()

AnotherActivity – is simple with TextView, MainActivity have only listview + onclick listener

  • 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-05-18T12:01:41+00:00Added an answer on May 18, 2026 at 12:01 pm
    private DatabaseHelper myDbHelper; 
    ...
    public void onStart() {
         DatabaseHelper myDbHelper = new DatabaseHelper(this);
    

    I removed the declaration DatabaseHelper in onStart. That fixed the ERROR/Cursor(1512)

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

Sidebar

Related Questions

Android newbie here. I'm using this tutorial to show some rows that I fetch
I'm an Android newbie so I apologize if this is a dumb question .
Still an Android newbie , but hopefully someone can point me in the right
Extreme Android developer newbie here...well, new to Android development, not development in general. I
NEWBIE ALERT! Here's the situation. I've got an Android ListActivity class (AppWindow) that contains
Im still a newbie in android, would appreciate your help as I couldnt find
I'm a newbie in android. Could anyone help me to find out tutorials which
I am a newbie to android. And feels like TDD can reduce developing time
I have a newbie android question: Why arent strings and other resources like colors
I'm a newbie on android development. I've been working on this app for my

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.