0

[Not a Duplicate] This question is about a searching functionality that caused my app to crash, just need to know if there is something wrong in my search method.

I have a simple searching class with a textbox and a button but only want to get the functionality done however the app is crashing on me as soon as I click on search button. Its meant to output 3 columns where it searches the name in textbox.

I tried getting all the data which that fully works that's in a different fragment and typed the exact values which I needed to be entering but I'm not sure what I'm doing wrong here.

Searching method in Database class;

    public String searchData(String name) {
    SQLiteDatabase db = this.getWritableDatabase();
    //gonna get calories and quantity only
    String[] columns = {COL_1, COL_2, COL_3};
    //searching for name
    Cursor cursor = db.query(TABLE_NAME, columns, COL_1+" = '"+name+"'", null, null, null, null);
    StringBuffer buffer = new StringBuffer();
    while (cursor.moveToNext()) {
        //returning name quantity and calories
        int columnName = cursor.getColumnIndex(COL_1);
        int columnQuantity = cursor.getColumnIndex(COL_2);
        int columnCalories = cursor.getColumnIndex(COL_3);

        String foodName = cursor.getString(columnName);
        String quantity = cursor.getString(columnQuantity);
        String calories = cursor.getString(columnCalories);

        buffer.append("Name: " + foodName + "\n" + "Serving size: " + quantity + "\n" + "Calories: " + calories);

    }
    return buffer.toString();

This is my fragment class where user inputs and clicks on the search button to search the data within the database;

 public void Search(View view) {
    searchButtonVariable.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String getNameText = searchTextVariable.getText().toString();
            String output = db.searchData(getNameText);
            showMessage("Data", output);
        }
    });

}

This is what I get in the logcat:

07-22 20:50:05.531 2265-5706/? W/ErrorReporter: reportError [type: 211, code: 524300]: Error reading from input stream
07-22 20:50:05.532 2265-2607/? I/MicroRecognitionRunner: Stopping hotword detection.
07-22 20:50:05.535 2265-5706/? W/ErrorProcessor: onFatalError, processing error from engine(4)
                                                 com.google.android.apps.gsa.shared.speech.b.g: Error reading from input stream
                                                     at com.google.android.apps.gsa.staticplugins.recognizer.j.a.a(SourceFile:28)
                                                     at com.google.android.apps.gsa.staticplugins.recognizer.j.b.run(SourceFile:15)
                                                     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:14)
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.bl.run(SourceFile:4)
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.bl.run(SourceFile:4)
                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                     at java.lang.Thread.run(Thread.java:764)
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.ai.run(SourceFile:6)
                                                  Caused by: com.google.android.apps.gsa.shared.exception.GsaIOException: Error code: 393238 | Buffer overflow, no available space.
                                                     at com.google.android.apps.gsa.speech.audio.Tee.f(SourceFile:103)
                                                     at com.google.android.apps.gsa.speech.audio.au.read(SourceFile:2)
                                                     at java.io.InputStream.read(InputStream.java:101)
                                                     at com.google.android.apps.gsa.speech.audio.ao.run(SourceFile:18)
                                                     at com.google.android.apps.gsa.speech.audio.an.run(SourceFile:2)
                                                     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457) 
                                                     at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.ax.run(SourceFile:14) 
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.bl.run(SourceFile:4) 
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.bl.run(SourceFile:4) 
                                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
                                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
                                                     at java.lang.Thread.run(Thread.java:764) 
                                                     at com.google.android.apps.gsa.shared.util.concurrent.a.ai.run(SourceFile:6) 
Dave
  • 1
  • 2

1 Answers1

0

use this query

Cursor c = db.rawQuery(
            "select * from table_name where column_name = ?",
            new String[] { name });
Salman500
  • 1,213
  • 1
  • 17
  • 35