• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Gridview Display from SQLLITE DATABASE

avictoria

Lurker
Hi,
I would like to read data from my sqllite database. below my code but i am getting error . "Cannot resolve method maketext java.lang.exception,int)

Code:

Code:
package in.whomeninja.android_barcode_scanner;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class ShowProduct extends Activity {
   [USER=1021285]@override[/USER]
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.showproduct);

       GridView gvproduct=(GridView)findViewById(R.id.gvproduct);
       List<String> li=new ArrayList<>();
       ArrayAdapter<String> dataAdapter=new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_spinner_item,li);
       dataAdapter.setDropDownViewResource(R.layout.showproduct);

       try {
           SQLiteDatabase db=openOrCreateDatabase("coke_db",MODE_PRIVATE,null);
           Cursor cr=db.rawQuery("SELECT * FROM PRODUCT_TBL",null);
           if(cr!=null){
               if(cr.moveToFirst()){
                   do{

                       String no=cr.getString(cr.getColumnIndex("barcodeResult"));
                       String name=cr.getString(cr.getColumnIndex("latitude_textview"));
                       String type=cr.getString(cr.getColumnIndex("longitude_textview"));
                       String qty=cr.getString(cr.getColumnIndex("textView1"));

                       String remark=cr.getString(cr.getColumnIndex("textView6"));

                       //li.add(no);
                       li.add(no);
                       li.add(name);
                       li.add(type);
                       li.add(qty);
                       li.add(remark);
                       gvproduct.setAdapter(dataAdapter);

                   }while (cr.moveToNext());

               }else{
                   Toast.makeText(getApplicationContext(), "No Data to show", Toast.LENGTH_LONG).show();

               }
           }

       }catch (Exception e){
           Toast.makeText(ShowProduct.this, e, Toast.LENGTH_SHORT).show();
       }

   }
}
 
Last edited by a moderator:
Error is due to your second parameter, which should be a String, not an Exception. The correct line is

Code:
Toast.makeText(ShowProduct.this, e.getMessage(), Toast.LENGTH_SHORT).show();
 
Btw welcome to Android Forums. The Application Development forum is the correct place to post programming questions.
Also, please put any code fragments within [code][/code] tags. And read the "Read me first" sticky post at the top of this forum, which contains some useful tips for new developers.
 
Error is due to your second parameter, which should be a String, not an Exception. The correct line is

Code:
Toast.makeText(ShowProduct.this, e.getMessage(), Toast.LENGTH_SHORT).show();

Hello LV,

Thanks but i am getting error even with e.getMessage "03-05 21:38:04.415 2459-2459/in.whomeninja.android_barcode_scanner E/CursorWindow: Failed to read row 0, column -1 from a CursorWindow which has 1 rows, 6 columns."
 
Back
Top Bottom