草庐IT

Android SQLite 在 170 行后崩溃

coder 2023-07-21 原文

如何更改此逻辑以处理超过 170 行。

// Getting All test 
public List<Test> getAllTests(String str) {
    List<Test> testList = new ArrayList<Test>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_TESTS;

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

   // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            //select rows by input string   
            if(cursor.getString(1).equals(str)){
                Test test = new Test();
                test.setId(Integer.parseInt(cursor.getString(0)));
                test.setTest(cursor.getString(1));
                test .setResult(Integer.parseInt(cursor.getString(2)));

                // Adding test to list
                testList.add(test);
            }
        } while (cursor.moveToNext());
    }
    //close database 
    db.close();

    //return list data     
    return testList;
}

我想通过输入字符串选择所有行。它的逻辑在 150 行时完美运行,但在 160 行后工作缓慢并在 170 行时崩溃

最佳答案

how to change this logic to work with more than 170 rows?

// Getting All test 
public List<Test> getAllTests(String str) {
    List<Test> testList = new ArrayList<Test>();
    // Select All Query

    //String selectQuery = "SELECT  * FROM " + TABLE_TESTS;
String selectQuery = "SELECT id,result FROM " + TABLE_TESTS + " where name ='" + str + "'";
    // Now you are saving memory of one column. 

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

   // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
           Test test = new Test();
           // moved outside loop to prevent creating new object every time.
        do {
            //select rows by input string   
            //if(cursor.getString(1).equals(str)){
            // No need for if Codition any more
                test.setId(Integer.parseInt(cursor.getString(0)));
                //test.setTest(cursor.getString(1));
                test.setTest(str);
                test .setResult(Integer.parseInt(cursor.getString(2)));
                // Adding test to list
                testList.add(test);
            //}
        } while (cursor.moveToNext());
    }
    //close database 
    db.close();

    //return list data     
    return testList;
}

关于Android SQLite 在 170 行后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31872792/

有关Android SQLite 在 170 行后崩溃的更多相关文章

  1. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  2. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  3. ruby - 在多个线程中引用类方法会导致自动加载循环依赖崩溃 - 2

    代码:threads=[]Thread.abort_on_exception=truebegin#throwexceptionsinthreadssowecanseethemthreadseputs"EXCEPTION:#{e.inspect}"puts"MESSAGE:#{e.message}"end崩溃:.rvm/gems/ruby-2.1.3@req/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:478:inload_missing_constant':自动加载常量MyClass时检测到循环依赖稍加研究后,

  4. ruby - 执行过期异常使 Ruby 线程崩溃,但处理了 Timeout::Error - 2

    任何人都可以解释为什么当对方法的调用看起来像这样时我可能会看到这个堆栈(由HTTParty::post请求引起):beginresponse=HTTParty::post(url,options)rescuelogger.warn("Couldnotpostto#{url}")rescueTimeout::Errorlogger.warn("Couldnotpostto#{url}:timeout")end堆栈:/usr/local/lib/ruby/1.8/timeout.rb:64:in`timeout'/usr/local/lib/ruby/1.8/net/protocol.rb

  5. ruby - vim 使用 AutoComplPop 插件崩溃 - 2

    我使用vim编辑ruby​​文件,但是当我输入“.”时它崩溃了。我发现它是由AutoComplPop插件引起的。我该怎么办? 最佳答案 我找到了一种使用autocomplpop和filetype=ruby来防止vim崩溃的方法。将以下行放入您的.vimrcletg:acp_behaviorRubyOmniMethodLength=-1这将防止在您键入“.”时触发autocomplpop。(期间)这不是解决办法。(我不是vim插件程序员)祝你好运! 关于ruby-vim使用AutoComp

  6. ruby-on-rails - 自动加载路径和嵌套服务类在 Ruby 中崩溃 - 2

    我在Rails5项目的app/services文件夹下有多个加载/需要类的问题,我开始放弃这个问题。首先要明确的是,services/是我在整个项目中使用的简单PORO类,用于从Controller、模型等中抽象出大部分业务逻辑。树看起来像这样app/services/my_service/base.rbfunny_name.rbmy_service.rbmodels/funny_name.rb失败#1首先,当我尝试使用MyService.const_get('FunnyName')时,它从我的模型目录中获取了FunnyName。当我直接执行MyService::FunnyName时,

  7. ruby - unicorn 与 Ruby 2.4.1 导致奇怪的崩溃 - 2

    我正在从Ruby2.3.1升级到Ruby2.4.1,这样做之后,Unicorn似乎与新版本不兼容。我收到以下错误。我正在使用Unicorn5.1.0并尝试过Unicorn5.3.1无济于事。我是否需要使用不同的库而不是XCode工具进行编译?我在使用foremanstart和Procfile启动服务器后立即收到错误:webpack:bin/webpack-dev-servergulp:gulpredis:./scripts/start_redis_server.shsidekiq:bundleexecsidekiq-Cconfig/sidekiq.ymlannotations_serv

  8. ruby-on-rails - rails 如何在调用 ajax 删除表行后删除它? - 2

    如果我有一个链接-=link_to'ajaX',ajax_delete_link_path(link),data:{:confirm=>'Areyousure?',:remote=>true}有一条路线:get'ajax_delete_link/:id',to:'links#ajax_delete_link',as::ajax_delete_link和一个链接Controller:defajax_delete_link@link=Link.find(params[:id])@link.destroyrespond_todo|format|format.jsendend和ajax_del

  9. ruby - Heroku 应用程序崩溃并显示 'libruby.so.1.9: cannot open shared object file' - 2

    这个问题不太可能帮助任何future的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visitthehelpcenter.关闭10年前。我在部署这个应用程序时从未遇到过问题,但我刚刚推送,现在我遇到了这个奇怪的错误,它在堆栈中足够深,甚至没有被发送到Airbrake。我觉得这可能是Heroku的问题,可能与https://status.heroku.com/incidents/450有关。?你怎么看?2012-10-14T08:40:31+00:00heroku[web.1]:State

  10. ruby - 带有 ruby​​ 1.9.3 的 Heroku 导致许多不同的崩溃 - 2

    我使用Gemfile中的新gem重新部署我的heroku应用程序,它在启动时崩溃了/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in`require':libruby.so.1.9:cannotopensharedobjectfile:Nosuchfileordirectory-/app/vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.so(LoadError)无论我部

随机推荐