Problems with Databae


  1. Rootstonian

    Rootstonian Member

    Ok, I can open my database without error, but when I try the following, I get a "The local variable cur may not have been initialized" error on "cur" on line 2

    Cursor cur;
    int row_count = cur.getCount();
    Toast.makeText(this, row_count, 2000).show();

    Any ideas? :)

    Thanks

    Advertisement
    :
  2. id0001

    id0001 Well-Known Member

    that is because the variable 'cur' is not initialized and therefore equals 'null'.
    You can't do a 'getCount()' on 'null'

    make sure that your variable is initialized:
    Code (Text):
    1. Cursor cur = new Cursor();
  3. Rootstonian

    Rootstonian Member

    Wow, quick reply...thanks :)

    Now I get:

    Cannot instantiate the type Cursor
  4. id0001

    id0001 Well-Known Member

    if you'd googled it, you would have found out that Cursor is an interface, so it can't be instantiated. But you can get a Cursor object if you execute a select query on your database.
    I don't know how you access your database but it should have some query or select method which returns a Cursor object.
  5. Rootstonian

    Rootstonian Member

    Googling it soon as I got error message..thanks! :)
  6. Rootstonian

    Rootstonian Member

    Ok, getting better. LogCat is showing an error that it can't find "_id" in the table (but I know it's there as I can see the schema in sqlite3

    Code (Text):
    1.  
    2.     public Cursor getRow(long rowId) throws SQLException {
    3.      
    4.       Cursor myCursor =
    5.           myDataBase.query(true, "zip", new String[]    {
    6.            "_id", "zip", "city"},
    7.           "_id" + "=" + rowId, null, null, null, null, null);
    8.      
    9.       if (myCursor != null) {
    10.           myCursor.moveToFirst();
    11.       }
    12.       return myCursor;
    13.      
    14.     }
    15.     }
    16.  
  7. Rootstonian

    Rootstonian Member

    I have all the database kinks worked out...sort of.

    App has 2 radio buttons in a radiogroup with associate listener. I also have a button and associate button listener.

    I'm having problems getting the value of the radio button value in my button listener ...any ideas?

    tia
  8. id0001

    id0001 Well-Known Member

    in your onClickListener you can just read the value of your radiobutton
  9. Rootstonian

    Rootstonian Member

    Thanks, but it's gone beyond that now and I'm about sick :) LOL Was up till 4 in the morning working on this...now my damn database won't open.
    12-01 12:00:55.286: ERROR/Database(367): sqlite3_open_v2("C:/Users/david/workspace/ZipCode/assets/zipcode.db", &handle, 1, NULL) failed

    The db file is there in assets...I can see it. I can open it with SQL Lite Browser. I'm actually sick to my stomach at this point...

    Wiped out database, uninstalled application, rebooted laptop, create NEW database with NEW name and still won't open....ugh

    Also, this is a database created on my PC, NOT through the app. I might just try to create it in the app, but I need a pre-loaded database for the app...I really don't want to muck around loading it in the app...
  10. Rootstonian

    Rootstonian Member

    Oh, and I need to read the value of the Radio button in ANOTHER (the Button) listener :)
  11. id0001

    id0001 Well-Known Member

    You can't read a windows path.
  12. Rootstonian

    Rootstonian Member

    OMG...NEVER MIND....freakn' braces vs. parenthesis...man, I need better glasses!!!!!

    Ok, getting closer...but I"m really stuck on this one.

    Code (Text):
    1.  
    2. public class myProgram extends Activity {
    3.  
    4. Button searchButton;
    5.  
    6. //other stuff
    7. }
    8. public void onCreate(Bundle savedInstanceState) {
    9.  
    10.         /** Setup Search Button */
    11.        searchButton = (Button) findViewById(R.id.Search);
    12.        setSearchbutton();
    13.  // other stuff
    14. }
    15.     private void setSearchbutton() {
    16.        
    17.         searchButton.setOnClickListener {  // ERROR, Multiple Markers
    18.         new View.OnClickListener()
    19.         {
    20.             @Override public void onClick(View v) {returnRow();}
    21.         }  // ERROR, insert ';'
    22.       };
    23.     }
    24.  
    No errors in "returnRow()"; it's just my database call
  13. id0001

    id0001 Well-Known Member

    setOnClickListener is a method so you have to user () instead of {}

    like this:
    Code (Text):
    1.  
    2. public class myProgram extends Activity {
    3.  
    4. Button searchButton;
    5.  
    6. //other stuff
    7. }
    8. public void onCreate(Bundle savedInstanceState) {
    9.  
    10.         /** Setup Search Button */
    11.        searchButton = (Button) findViewById(R.id.Search);
    12.        setSearchbutton();
    13.  // other stuff
    14. }
    15.     private void setSearchbutton() {
    16.        
    17.            searchButton.setOnClickListener(
    18.            new View.OnClickListener() {
    19.               @Override
    20.               public void onClick(View v) {
    21.                   returnRow();
    22.               }
    23.            }
    24.         );
    25.     }
    26.  
    This is fairly standard java code. Maybe you should read some more tutorials about java.
    You should be able to figure out these errors by yourself.
  14. Rootstonian

    Rootstonian Member

    Maybe you shouldn't be so condescending. Nobody's perfect...and reading a tutorial is hardly going to teach me that.

    If I recall when searching for a decent developer forum and found this one, there is a sticky about users and their responses; perhaps YOU need to read it :) Basically boils down to "if you don't have anything good or helpful to say, then just don't say anything".

    Like I said, I caught the mistake and I need new glasses...my eyesight isn't that good and telling those apart is sometimes hard for me.
  15. miXer

    miXer Well-Known Member

    I don't think id0001 was condescending. He just said the truth. You should read up a bit more on java syntax, and you should check your code better before asking for help here. You probably should get a book. I can recommend this one: Hello Android
Loading...

Share This Page