问题在谷歌Android API上运行时(2.2平台) [英] Issue when running in a android google API (2.2 platform)

查看:160
本文介绍了问题在谷歌Android API上运行时(2.2平台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新来android开发,温柔哈哈。我想填充从我SQLite数据库数据的微调。我有一个表,它是pre-人口和我能够成功查询。问题是,我在emulater(Android 2.2的),但不能在我的便携设备(平板电脑和手机)上运行它运行时,它很能填充微调(运行Android 2.2)。我得到一个一般性错误消息说:applilcation ...(应用程序名称)......已意外停止,请重试。但是,我也注意到,我在模拟器它与构建路径被设置为的Andr​​oid 2.2,然而,当我将其更改为谷歌API(2.2平台),然后,我遇到它精美的作品。我失去了财产以后?这里是被用来填充微调控制code:

 最后DBAdapter DB =新DBAdapter(本);
    db.open();
    光标C = db.getAllStates();    startManagingCursor(C);
    的String [] =列新的String [] {} DBAdapter.KEY_STATE_NAME;
    INT []为= INT新[] {} android.R.id.text1;    SimpleCursorAdapter适配器=新SimpleCursorAdapter(这一点,android.R.layout.simple_spinner_item,C柱,至);    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);    //获取参考微调...
    微调S =(微调)findViewById(R.id.spinner_state);
    s.setAdapter(适配器);
    db.close();

下面是我的code来获得数据:

 公共光标getAllStates()
    {
        光标C = NULL;
                    C = db.query(DATABASE_TABLE_STATE,新的String [] {KEY_STATE_ID,KEY_STATE_NAME},NULL,NULL,NULL,NULL,NULL);
        // C = db.rawQuery(从tblStates选择*,NULL);        返回℃;
    }

LocCat:

 :信息/数据库(305):sqlite的返回:错误code = 1,味精=没有这样的表:tblStates
:DEBUG / AndroidRuntime(305):关闭VM
:WARN / dalvikvm(305):主题ID = 1:螺纹未捕获的异常退出(组= 0x4001d800)
:ERROR / AndroidRuntime(305):致命异常:主要
:ERROR / AndroidRuntime(305):了java.lang.RuntimeException:无法启动活动ComponentInfo {king.chad.SDE / king.chad.SDE.Bu​​ildingAddressActivity}
:android.database.sqlite.SQLiteException:没有这样的表:tblStates:,编译时:选择_id,Statename的FROM tblStates
:ERROR / AndroidRuntime(305):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)


解决方案

......经过一番搜索和头发拉我插破发点都在我的code和调试的地狱它才发现该目录(设备VS模拟器上运行时)无法找到。因此,它不能从我pre-填充这就解释了为什么该数据没有得到绑定到微调控制数据库中读取。因此,在我的活动我检查了目录的开始,如果它不存在我创造了它。问题解决了。如果其他人是否有相同的问题,因为我做了随意张贴,我会很高兴摆脱一下光我可以,感谢所有为您的建议!

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)

解决方案

...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!

这篇关于问题在谷歌Android API上运行时(2.2平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆