在 android google API(2.2 平台)中运行时出现问题

发布于 2024-12-06 12:50:49 字数 1961 浏览 1 评论 0原文

刚接触android开发,温柔一点,哈哈。我想用 SQLite 数据库中的数据填充微调器。我有一个预先填充的表,并且能够成功查询它。问题是,我能够在模拟器(android 2.2)中运行它时填充微调器,但无法在我的便携式设备(平板电脑和手机)(运行 android 2.2)上运行它。我收到一条通用错误消息:“应用程序...(应用程序名称)...已意外停止。请重试。”然而,我确实注意到,在我的模拟器中,它在构建路径设置为“Android 2.2”时工作得很好,但当我将其更改为 Google API(2.2 平台)时,我又遇到了它。我错过了什么吗?这是用于填充微调控件的代码:

 final DBAdapter db = new DBAdapter(this); 
    db.open(); 
    Cursor c = db.getAllStates();

    startManagingCursor(c);             
    String[] columns = new String[]{DBAdapter.KEY_STATE_NAME};
    int[] to = new int []{android.R.id.text1};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, columns, to);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    //get reference to the spinner...
    Spinner s =(Spinner) findViewById(R.id.spinner_state);
    s.setAdapter(adapter);


    db.close();

这是我获取数据的代码:

        public Cursor getAllStates() 
    {    
        Cursor c = null;
                    c = db.query(DATABASE_TABLE_STATE, new String[] { KEY_STATE_ID, KEY_STATE_NAME }, null, null, null, null, null);


        //c = db.rawQuery("select * from tblStates", null);

        return c;   
    }

LocCat:

: INFO/Database(305): sqlite returned: error code = 1, msg = no such table: tblStates
: DEBUG/AndroidRuntime(305): Shutting down VM
: WARN/dalvikvm(305): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
: ERROR/AndroidRuntime(305): FATAL EXCEPTION: main
: ERROR/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{king.chad.SDE/king.chad.SDE.BuildingAddressActivity}
: android.database.sqlite.SQLiteException: no such table: tblStates: , while compiling: SELECT _id, stateName FROM tblStates
: ERROR/AndroidRuntime(305):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

New to android development, be gentle haha. I am wanting to populate a spinner with data from my SQLite database. I have a table that is pre-populated and am able to query it successfully. Problem is that I am able to populate the spinner when running it in my emulater (android 2.2) but not able to run it on my portable devices (tablet and phone) (running android 2.2). I get a generic error message saying that: "applilcation...(app name)...has stopped unexpectedly. Please try again." However, I did notice that in my emulator it works beautifully with the build path being set to "Android 2.2" and yet when I change it to the Google API (2.2 platform), I then encounter it. Am I missing somthing? here is the code being used to populate the spinner control:

 final DBAdapter db = new DBAdapter(this); 
    db.open(); 
    Cursor c = db.getAllStates();

    startManagingCursor(c);             
    String[] columns = new String[]{DBAdapter.KEY_STATE_NAME};
    int[] to = new int []{android.R.id.text1};

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, columns, to);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    //get reference to the spinner...
    Spinner s =(Spinner) findViewById(R.id.spinner_state);
    s.setAdapter(adapter);


    db.close();

Here is my code to get the data:

        public Cursor getAllStates() 
    {    
        Cursor c = null;
                    c = db.query(DATABASE_TABLE_STATE, new String[] { KEY_STATE_ID, KEY_STATE_NAME }, null, null, null, null, null);


        //c = db.rawQuery("select * from tblStates", null);

        return c;   
    }

LocCat:

: INFO/Database(305): sqlite returned: error code = 1, msg = no such table: tblStates
: DEBUG/AndroidRuntime(305): Shutting down VM
: WARN/dalvikvm(305): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
: ERROR/AndroidRuntime(305): FATAL EXCEPTION: main
: ERROR/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{king.chad.SDE/king.chad.SDE.BuildingAddressActivity}
: android.database.sqlite.SQLiteException: no such table: tblStates: , while compiling: SELECT _id, stateName FROM tblStates
: ERROR/AndroidRuntime(305):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惯饮孤独 2024-12-13 12:50:49

...经过大量搜索和头发拉扯后,我在整个代码中插入了断点,并对其进行了彻底的调试,结果发现无法找到该目录(在设备与模拟器上运行时)。因此,它无法从我预先填充的数据库中读取数据,这解释了为什么数据没有绑定到微调器控件。因此,在我的活动开始时,我检查了该目录,如果它不存在,我就创建它。问题解决了。如果其他人也遇到与我相同的问题,请随时发帖,我将很高兴尽我所能,感谢大家的建议!

...after much searching and hair pulling I inserted break points all throughout my code and debugged the hell out of it only to find that the directory (when running on the device vs the emulator) could not be found. Therefore it couldn't read from the database that I pre-populated which explains why the data wasn't getting binded to the spinner control. So at the beginning of my activity I checked for the directory and if it didn't exist I created it. Problem resolved. If anyone else is having same issue as I did feel free to post and I'll be glad to shed what light I can, thanks to all for your suggestions!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文