java - 如何使用另一列仅获取一列数据

标签 java android-studio

逻辑错误..我是 Android java 数据库的新手..没有错误,但我想你们明白我的意思。

getSearch = searchbar.getText() .toString();
searchquery = "SELECT * FROM words WHERE tagalog LIKE '%"+ getSearch +"%';";
sqLiteDatabase.rawQuery(searchquery,null);
Cursor c = wordsDBHelper.getdata(sqLiteDatabase);
searchRes.setText( c.getString(2).toString());

任何建议都会被接受。按下此代码所在的按钮后,按钮将直接指向 mainActivity。

heres the logcat
    01-26 13:28:49.285 32177-32177/? D/dalvikvm: Late-enabling CheckJNI
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve interface method 17980: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve interface method 17984: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-26 13:28:49.305 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-26 13:28:49.315 32177-32177/com.example.leoandroid.translate D/dalvikvm: GC_FOR_ALLOC freed 125K, 27% free 2723K/3728K, paused 10ms, total 10ms
01-26 13:28:49.315 32177-32177/com.example.leoandroid.translate I/dalvikvm-heap: Grow heap (frag case) to 7.125MB for 4651212-byte allocation
01-26 13:28:49.325 32177-32183/com.example.leoandroid.translate D/dalvikvm: GC_FOR_ALLOC freed <1K, 13% free 7265K/8272K, paused 10ms, total 10ms
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve virtual method 433: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate W/dalvikvm: VFY: unable to resolve virtual method 455: Landroid/content/res/TypedArray;.getType (I)I
01-26 13:28:49.355 32177-32177/com.example.leoandroid.translate D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-26 13:28:49.435 32177-32177/com.example.leoandroid.translate I/PGA: Attempting to create new SOCKET connectionn pid = 32177, tid = 32177
01-26 13:28:49.445 32177-32177/com.example.leoandroid.translate I/PGA: New SOCKET connection: com.example.leoandroid.translate (pid 32177, tid 32177)

请帮忙。我尝试分析它并分析了尝试创建新的套接字连接...将其重定向到主要 Activity ?我很困惑。

最佳答案

更好地利用功能。在 DbHelper 类中创建函数,例如

     public DataProvider getInformations()
         { 
                  SQLiteDatabase db = this.getReadableDatabase();
                  Cursor res =  db.rawQuery( "select "+your column+" from "+TABLE_NAME, null );
                    res.moveToFirst();
                    DataProvider dataProvider = new DataProvider();
                    while(res.isAfterLast() == false)
                    {
                        dataProvider.setText(res.getString(res.getColumnIndex(Columnname)));
                        res.moveToNext();
                    }
                db.close();
                return dataProvider;
         }

然后是您的主要 Activity

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);

    userDbHelper =new UserDbHelper(this);
    DataProvider dataProvider=userDbHelper.getInformations();
    text = dataProvider.getText();

    }

关于java - 如何使用另一列仅获取一列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41858053/

相关文章:

java - 用于以 XML/JSON 和 API 表示图形/网络数据以进行遍历的标准规范格式

java - Rails 类似于 Java 的数据库抽象

java - android studio 编辑器恢复到旧文件然后是当前本地

java - 在哪里创建 LibGDX And​​roid Studio 的 asset 文件夹

java - NoClassDefFoundError : org/apache/commons/lang/StringUtils

java - Spring Security - 启用 HTTPS 时登录不起作用

java - 为什么我的 avrokey 数据说它是一个通用记录当我明确地将数据写为 AvroKey<SpecificRecord> 时?

android - Android Studio 中编辑器折叠和区域注释的区别

android - 在设备上运行但可在模拟器中运行的Android应用程序崩溃

java - 隐藏状态栏中的通知效果。安卓编程