Aller au contenu

Listview Sqlite


Recommended Posts

Bonjour tout le monde,

J'ai besoin de votre soutien. Je veux bien chercher dans une listview un item selon le edittext saisie; J ai donc crée un DBADapter avec une methode OffreRecherche. Dans l'activité quand je veux recuperer editText et les faires passer dans la methode OffreRecherche ça marche pas :

DBAddapter.java:

 

  public Cursor RechercheOffre(String titre, String qualiterequises) throws SQLException 
   {
   
            return  db.rawQuery("SELECT * FROM " + DATABASE_TABLE_OFFRE + " WHERE titre=? OR qualiterequises=?", new String[]{titre,qualiterequises});
           
       
   }
 
 
 
OffreListRecherche.java:
public class OffreListRecherche extends ListActivity{
public static final String ROW_ID = "row_id";
private ListView conListView;
private CursorAdapter conAdapter;
TextView t1,t2;
private String titre,qualite;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        conListView=getListView();
        conListView.setOnItemClickListener(viewConListener);
        
        // map each name to a TextView
        String[] from = new String[] { "titre","qualiterequises","localisation" };
        int[] to = new int[] { R.id.offreTextView ,R.id.qualiter,R.id.local};
        conAdapter = new SimpleCursorAdapter(OffreListRecherche.this, R.layout.offre_list, null, from, to);
        setListAdapter(conAdapter); // set adapter
        t2=(TextView)findViewById(R.id.localisation);
        t1=(TextView)findViewById(R.id.offreTextView);
        Intent intent = getIntent();
        titre = intent.getStringExtra("titre");
           qualite = intent.getStringExtra("qualite");
           
    }
    
    
  
 
@Override
    protected void onResume() 
    {
       super.onResume(); 
       new GetContacts().execute(titre,qualite);
       
     } 
    
    
    @Override
    protected void onStop() 
    {
       Cursor cursor = conAdapter.getCursor();
       
       if (cursor != null) 
          cursor.deactivate();
       
       conAdapter.changeCursor(null);
       super.onStop();
    }    
    
  
    private class GetContacts extends AsyncTask<String, Object, Cursor> 
    {
    
 
      DBAdapter db = new DBAdapter(OffreListRecherche.this);
 
       @Override
       protected Cursor doInBackground(String... params)
       {System.out.println(""+params[0]+""+params[1]);
          db.open();
          return db.RechercheOffre(params[0],params[1]); 
       } 
       
       @Override
       protected void onPostExecute(Cursor result)
       {   super.onPostExecute(result); 
          conAdapter.changeCursor(result); // set the adapter's Cursor
          db.close();
          
       } 
    } 
   
 
       
    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
       super.onCreateOptionsMenu(menu);
       MenuInflater inflater = getMenuInflater();
       inflater.inflate(R.menu.offre_menu, menu);
       return true;
    }   
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
       Intent addOffre = new Intent(OffreListRecherche.this, AjoutOffre.class);
       startActivity(addOffre);
       return super.onOptionsItemSelected(item);
    }
    
    OnItemClickListener viewConListener = new OnItemClickListener() 
    {
       public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
       {         
          Intent viewCon = new Intent(OffreListRecherche.this, ViewOffre.class);
          viewCon.putExtra(ROW_ID, arg3);
          startActivity(viewCon);
       }
     };    
     
 }
   
 
 
 
Et comme erreur:
 
08-17 03:40:41.552: D/dalvikvm(17679): GC_EXTERNAL_ALLOC freed 945 objects / 64368 bytes in 92ms
08-17 03:40:46.322: W/KeyCharacterMap(17679): No keyboard for id 0
08-17 03:40:46.322: W/KeyCharacterMap(17679): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
08-17 03:40:57.461: I/System.out(17679): nullnull
08-17 03:40:57.821: W/dalvikvm(17679): threadid=8: thread exiting with uncaught exception (group=0x4001d800)
08-17 03:40:57.861: E/AndroidRuntime(17679): FATAL EXCEPTION: AsyncTask #1
08-17 03:40:57.861: E/AndroidRuntime(17679): java.lang.RuntimeException: An error occured while executing doInBackground()
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.lang.Thread.run(Thread.java:1096)
08-17 03:40:57.861: E/AndroidRuntime(17679): Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:234)
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:182)
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
08-17 03:40:57.861: E/AndroidRuntime(17679): at ma.example.stage.DBAdapter.RechercheOffre(DBAdapter.java:145)
08-17 03:40:57.861: E/AndroidRuntime(17679): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:82)
08-17 03:40:57.861: E/AndroidRuntime(17679): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:1)
08-17 03:40:57.861: E/AndroidRuntime(17679): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-17 03:40:57.861: E/AndroidRuntime(17679): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-17 03:40:57.861: E/AndroidRuntime(17679): ... 4 more
08-17 03:40:58.061: I/System.out(17679): Annonce1Developpeur
08-17 03:45:58.008: I/Process(17679): Sending signal. PID: 17679 SIG: 9
08-17 03:45:58.621: D/dalvikvm(17947): GC_EXTERNAL_ALLOC freed 972 objects / 65408 bytes in 72ms
08-17 04:04:17.242: I/System.out(17947): nullnull
08-17 04:04:17.602: W/dalvikvm(17947): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
08-17 04:04:17.642: E/AndroidRuntime(17947): FATAL EXCEPTION: AsyncTask #1
08-17 04:04:17.642: E/AndroidRuntime(17947): java.lang.RuntimeException: An error occured while executing doInBackground()
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.lang.Thread.run(Thread.java:1096)
08-17 04:04:17.642: E/AndroidRuntime(17947): Caused by: java.lang.IllegalArgumentException: the bind value at index 1 is null
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:234)
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.database.sqlite.SQLiteQuery.bindString(SQLiteQuery.java:182)
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
08-17 04:04:17.642: E/AndroidRuntime(17947): at ma.example.stage.DBAdapter.RechercheOffre(DBAdapter.java:145)
08-17 04:04:17.642: E/AndroidRuntime(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:82)
08-17 04:04:17.642: E/AndroidRuntime(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:1)
08-17 04:04:17.642: E/AndroidRuntime(17947): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-17 04:04:17.642: E/AndroidRuntime(17947): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-17 04:04:17.642: E/AndroidRuntime(17947): ... 4 more
08-17 04:04:17.792: D/dalvikvm(17947): GC_FOR_MALLOC freed 10742 objects / 352112 bytes in 107ms
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: SELECT * FROM offre WHERE titre=? OR qualiterequises=?
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at ma.example.stage.DBAdapter.RechercheOffre(DBAdapter.java:145)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:82)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:1)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-17 04:04:17.792: W/SQLiteCompiledSql(17947): at java.lang.Thread.run(Thread.java:1096)
08-17 04:04:17.843: E/Database(17947): close() was never explicitly called on database '/data/data/ma.androidmag.authenificationm1/databases/sqlite.db' 
08-17 04:04:17.843: E/Database(17947): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
08-17 04:04:17.843: E/Database(17947): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1810)
08-17 04:04:17.843: E/Database(17947): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
08-17 04:04:17.843: E/Database(17947): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:851)
08-17 04:04:17.843: E/Database(17947): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:844)
08-17 04:04:17.843: E/Database(17947): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:540)
08-17 04:04:17.843: E/Database(17947): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
08-17 04:04:17.843: E/Database(17947): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
08-17 04:04:17.843: E/Database(17947): at ma.example.stage.DBAdapter.open(DBAdapter.java:51)
08-17 04:04:17.843: E/Database(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:81)
08-17 04:04:17.843: E/Database(17947): at ma.example.stage.offre.OffreListRecherche$GetContacts.doInBackground(OffreListRecherche.java:1)
08-17 04:04:17.843: E/Database(17947): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-17 04:04:17.843: E/Database(17947): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-17 04:04:17.843: E/Database(17947): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-17 04:04:17.843: E/Database(17947): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-17 04:04:17.843: E/Database(17947): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-17 04:04:17.843: E/Database(17947): at java.lang.Thread.run(Thread.java:1096)
08-17 04:04:17.872: E/Cursor(17947): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/ma.androidmag.authenificationm1/databases/sqlite.db, table = null, query = SELECT * FROM offre WHERE titre=? OR qualiterequises=?
08-17 04:04:17.872: E/Cursor(17947): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
08-17 04:04:17.872: E/Cursor(17947): at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
08-17 04:04:17.872: E/Cursor(17947): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
08-17 04:04:17.872: E/Cursor(17947): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
08-17 04:04:17.872: E/Cursor(17947): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
08-17 04:04:17.872: E/Cursor(17947): at ma.example.stage.DBAdapter.RechercheOffre1(DBAdapter.java:151)
08-17 04:04:17.872: E/Cursor(17947): at ma.example.stage.MainActivity.onClick(MainActivity.java:74)
08-17 04:04:17.872: E/Cursor(17947): at android.view.View.performClick(View.java:2408)
08-17 04:04:17.872: E/Cursor(17947): at android.view.View$PerformClick.run(View.java:8816)
08-17 04:04:17.872: E/Cursor(17947): at android.os.Handler.handleCallback(Handler.java:587)
08-17 04:04:17.872: E/Cursor(17947): at android.os.Handler.dispatchMessage(Handler.java:92)
08-17 04:04:17.872: E/Cursor(17947): at android.os.Looper.loop(Looper.java:123)
08-17 04:04:17.872: E/Cursor(17947): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-17 04:04:17.872: E/Cursor(17947): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 04:04:17.872: E/Cursor(17947): at java.lang.reflect.Method.invoke(Method.java:521)
08-17 04:04:17.872: E/Cursor(17947): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-17 04:04:17.872: E/Cursor(17947): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-17 04:04:17.872: E/Cursor(17947): at dalvik.system.NativeStart.main(Native Method)
08-17 04:04:17.932: I/System.out(17947): Annonce1Developpeur
 

 

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...