Aller au contenu

[AIDE] Pb pour ma base sql ...


Recommended Posts

voila je vais stocker des int et ca bug.. l'apply s'arrete... c'est du a la base de donnée car quand je l'enleve ca marche...

code :

d'abors je remerci ceux qui oseront regarder ce code... car le nombre aléatoire prend la valeur donnée dans le code donc il y a dans test un tres long if else if else if etc... mais on comprend comment ca marche

test et stats controler par onglet

et dbadapter qui controle la base

dbadapter

package fr.tecknologiks.testanglais;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.view.View.OnClickListener;

public class DBAdapter {


       public static final String KEY_ROWID = "_id";
       public static final String KEY_ISBN = "0";
       public static final String KEY_TITLE = "0";
       private static final String TAG = "DBAdapter";

       private static final String DATABASE_NAME = "scores";
       private static final String DATABASE_TABLE = "titles";
       private static final int DATABASE_VERSION = 1;

       private static final String DATABASE_CREATE =
           "create table titles (_id integer primary key autoincrement, ";

       private final Context context; 

       private DatabaseHelper DBHelper;
       private SQLiteDatabase db;

       public DBAdapter(Context onClickListener) 
       {
           this.context = onClickListener;
           DBHelper = new DatabaseHelper(context);
       }

       private static class DatabaseHelper extends SQLiteOpenHelper 
       {
           DatabaseHelper(Context context) 
           {
               super(context, DATABASE_NAME, null, DATABASE_VERSION);
           }

           @Override
           public void onCreate(SQLiteDatabase db) 
           {
               db.execSQL(DATABASE_CREATE);
           }

           @Override
           public void onUpgrade(SQLiteDatabase db, int oldVersion, 
           int newVersion) 
           {
               Log.w(TAG, "Upgrading database from version " + oldVersion 
                       + " to "
                       + newVersion + ", which will destroy all old data");
               db.execSQL("DROP TABLE IF EXISTS titles");
               onCreate(db);
           }
       }    

       //---opens the database---
       public DBAdapter open() throws SQLException 
       {
           db = DBHelper.getWritableDatabase();
           return this;
       }

       //---closes the database---    
       public void close() 
       {
           DBHelper.close();
       }

       //---insert a title into the database---
       public long insertTitle(int isbn, int title) 
       {
           ContentValues initialValues = new ContentValues();
           initialValues.put(KEY_ISBN, isbn);
           initialValues.put(KEY_TITLE, title);
           return db.insert(DATABASE_TABLE, null, initialValues);
       }

       //---deletes a particular title---
       public boolean deleteTitle(long rowId) 
       {
           return db.delete(DATABASE_TABLE, KEY_ROWID + 
                   "=" + rowId, null) > 0;
       }

       //---retrieves all the titles---
       public Cursor getAllTitles() 
       {
           return db.query(DATABASE_TABLE, new String[] {
                   KEY_ROWID, 
                   KEY_ISBN,
                   KEY_TITLE,},
                   null, 
                   null, 
                   null, 
                   null, 
                   null);
       }

       //---retrieves a particular title---
       public Cursor getTitle(long rowId) throws SQLException 
       {
           Cursor mCursor =
                   db.query(true, DATABASE_TABLE, new String[] {
                           KEY_ROWID,
                           KEY_ISBN, 
                           KEY_TITLE,
                           }, 
                           KEY_ROWID + "=" + rowId, 
                           null,
                           null, 
                           null, 
                           null, 
                           null);
           if (mCursor != null) {
               mCursor.moveToFirst();
           }
           return mCursor;
       }

       //---updates a title---
       public boolean updateTitle(long rowId, int isbn, 
       int title) 
       {
           ContentValues args = new ContentValues();
           args.put(KEY_ISBN, isbn);
           args.put(KEY_TITLE, title);
           return db.update(DATABASE_TABLE, args, 
                            KEY_ROWID + "=" + rowId, null) > 0;
       }

   }

test

package fr.tecknologiks.testanglais;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Test extends Activity {

   private EditText editText;
   private Button button;
   private String hello;
   private String verbe;
   private String verbeq;
   private String verbep;
   private String verbepp;
   private Button reload;
   int nombre;
   int reponseb = 0;
   int reponsef = 0;

   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
        DBAdapter db = new DBAdapter(this);    

       reload = (Button) findViewById(R.id.refresh);
       ((TextView)findViewById(R.id.verbe)).setText("appuyer sur Nouveau Verbe");                    

       reload.setOnClickListener(
               //choix du nb aleatoire et pointer verbe
               new OnClickListener() {
               public void onClick(View v) {
                   nombre = (int) (Math.random() * 33 + 1);
                   if (nombre == 1){
                       verbeq = "parier";
                       verbe = "bet";
                       verbep = "bet";
                       verbepp = "bet";
                   } else if (nombre == 2){
                       verbeq = "éclater";
                       verbe = "burst";
                       verbep = "burst";
                       verbepp = "burst";
                   } else if (nombre == 3){
                       verbeq = "coûter";
                       verbe = "cost";
                       verbep = "cost";
                       verbepp = "cost";
                   } else if (nombre == 4){
                       verbeq = "couper";
                       verbe = "cut";
                       verbep = "cut";
                       verbepp = "cut";
                   } else if (nombre == 5){
                       verbeq = "frapper/atteindre";
                       verbe = "hit";
                       verbep = "hit";
                       verbepp = "hit";
                   } else if (nombre == 6){
                       verbeq = "blesser";
                       verbe = "hurt";
                       verbep = "hurt";
                       verbepp = "hurt";
                   } else if (nombre == 7){
                       verbeq = "permettre/louer";
                       verbe = "let";
                       verbep = "let";
                       verbepp = "let";
                   } else if (nombre == 8){
                       verbeq = "mettre/poser";
                       verbe = "put";
                       verbep = "put";
                       verbepp = "put";
                   }else if (nombre == 9){
                       verbeq = "lire";
                       verbe = "read";
                       verbep = "read";
                       verbepp = "read";
                   } else if (nombre == 10){
                       verbeq = "fixer";
                       verbe = "set";
                       verbep = "set";
                       verbepp = "set";
                   } else if (nombre == 11){
                       verbeq = "fermer";
                       verbe = "shut";
                       verbep = "shut";
                       verbepp = "shut";
                   } else if (nombre == 12){
                       verbeq = "fendre";
                       verbe = "split";
                       verbep = "split";
                       verbepp = "split";
                   } else if (nombre == 13){
                       verbeq = "répandre/étaler";
                       verbe = "spread";
                       verbep = "spread";
                       verbepp = "spread";
                   } else if (nombre == 14){
                       verbeq = "bouleverser";
                       verbe = "upset";
                       verbe = "upset";
                       verbepp = "upset";
                   } else if (nombre == 15){
                       verbeq = "(se) courber";
                       verbe = "bend";
                       verbep = "bent";
                       verbepp = "bent";
                   } else if (nombre == 16){
                       verbeq = "lier/relier";
                       verbe = "bind";
                       verbep = "bound";
                       verbepp = "bound";
                      } else if (nombre == 17){
                          verbeq = "saigner";
                          verbe = "bleed";
                          verbep = "bled";
                          verbepp = "bled";
                      } else if (nombre == 18){
                          verbeq = "élever (bétail)";
                          verbe = "breed";
                          verbep = "bred";
                          verbepp = "bred";
                      } else if (nombre == 18){
                          verbeq = "apporter";
                          verbe = "bring";
                          verbep = "brought";
                          verbepp = "brought";
                      } else if (nombre == 19){
                          verbeq = "construire";
                          verbe = "build";
                          verbep = "built";
                          verbepp = "built";
                      } else if (nombre == 20){
                          verbeq = "bruler";
                          verbe = "burn";
                          verbep = "burnt";
                          verbepp = "burnt";
                      } else if (nombre == 21){
                          verbeq = "acheter";
                          verbe = "buy";
                          verbep = "bought";
                          verbepp = "bought";
                      } else if (nombre == 22){
                          verbeq = "attraper";
                          verbe = "catch";
                          verbep = "caught";
                          verbepp = "caught";
                      } else if (nombre == 23){
                          verbeq = "s'accrocher";
                          verbe = "cling";
                          verbep = "clung";
                          verbepp = "clung";
                      } else if (nombre == 24){
                          verbeq = "ramper";
                          verbe = "creep";
                          verbep = "crept";
                          verbepp = "crept";
                      } else if (nombre == 25){
                          verbeq = "distribuer";
                          verbe = "deal";
                          verbep = "dealt";
                          verbepp = "dealt";
                      } else if (nombre == 26){
                          verbeq = "creuser";
                          verbe = "dig";
                          verbep = "dug";
                          verbepp = "dug";
                      } else if (nombre == 27){
                          verbeq = "rever";
                          verbe = "dream";
                          verbep = "dreamt";
                          verbepp = "dreamt";
                      } else if (nombre == 28){
                          verbeq = "(se) nourrir";
                          verbe = "feed";
                          verbep = "fed";
                          verbepp = "fed";
                      } else if (nombre == 29){
                          verbeq = "(se) sentir/éprouver";
                          verbe = "feel";
                          verbep = "felt";
                          verbepp = "felt";
                      } else if (nombre == 30){
                          verbeq = "se battre/combattre";
                          verbe = "fight";
                          verbep = "fought";
                          verbepp = "fought";
                      } else if (nombre == 31){
                          verbeq = "trouver";
                          verbe = "find";
                          verbep = "found";
                          verbepp = "found";
                      } else if (nombre == 32){
                          verbeq = "s'enfuir";
                          verbe = "flee";
                          verbep = "fled";
                          verbepp = "fled"; 
                      } else if (nombre == 33){
                          verbeq = "obtenir";
                          verbe = "get";
                          verbep = "got";
                          verbepp = "got";
                      } else if (nombre == 34){
                          verbeq = "prendre/accrocher";
                          verbe = "hang";
                          verbep = "hung";
                          verbepp = "hung";
                      } else if (nombre == 35){
                          verbeq = "avoir";
                          verbe = "have";
                          verbep = "had";
                          verbepp = "had";
                      } else if (nombre == 36){
                          verbeq = "entendre";
                          verbe = "hear";
                          verbep = "heard";
                          verbepp = "heard";
                      } else if (nombre == 37){
                          verbeq = "tenir";
                          verbe = "hold";
                          verbep = "held";
                          verbepp = "held";
                      } else if (nombre ==38){
                          verbeq = "garder";
                          verbe = "keep";
                          verbep = "kept";
                          verbepp = "kept";
                      } else if (nombre == 39){
                          verbeq = "s'agenouiller";
                          verbe = "kneel";
                          verbep = "knelt";
                          verbepp = "knelt";
                      } else if (nombre == 40){
                          verbeq = "poser a plat";
                          verbe = "lay";
                          verbep = "laid";
                          verbepp = "laid";
                      } else if (nombre == 41){
                          verbeq = "mener/guider";
                          verbe = "lead";
                          verbep = "led";
                          verbepp = "led";
                      } else if (nombre == 42){
                          verbeq = "s'appuyer";
                          verbe = "lean";
                          verbep = "leant";
                          verbepp = "leant";
                      } else if (nombre == 43){
                          verbeq = "sauter";
                          verbe = "leap";
                          verbep = "leapt";
                          verbepp = "leapt";
                      } else if (nombre == 44){
                          verbeq = "apprendre";
                          verbe = "learn";
                          verbep = "learnt";
                          verbepp = "learnt";
                      } else if (nombre == 45){
                          verbeq = "laisser/quitter";
                          verbe = "leave";
                          verbep = "left";
                          verbepp = "left";
                      } else if (nombre == 46){
                          verbeq = "prêter";
                          verbe = "lend";
                          verbep = "lent";
                          verbepp = "lent";
                      } else if (nombre == 47){
                          verbeq = "allumer";
                          verbe = "light";
                          verbep = "lit";
                          verbepp = "lit";
                      } else if (nombre == 48){
                          verbeq = "perdre";
                          verbe = "lose";
                          verbep = "lost";
                          verbepp = "lost";
                      } else if (nombre == 49){

                      }

               ((TextView)findViewById(R.id.verbe)).setText("Verbe en francais: " + verbeq);                    
                 }
               }
               );    


       //récupération de l'EditText grâce à son ID
       editText = (EditText) findViewById(R.id.question);

       //récupération du bouton grâce à son ID
       button = (Button) findViewById(R.id.Button);

       //on applique un écouteur d'évenement au clique sur le bouton
       button.setOnClickListener(
           new OnClickListener() {
           @Override
           public void onClick(View v) {
               //on réupère le texte écrit dans l'EditText
               hello = editText.getText().toString();


                 if (hello.equals(verbe)){
                     ((TextView)findViewById(R.id.Resultat)).setText("Bonne réponse");                    
                     ((TextView)findViewById(R.id.Resultat2)).setText("Réponse: " + hello);                    
                     Toast.makeText(Test.this,    "Bonne réponse ! :)", Toast.LENGTH_LONG).show();
                     reponseb++;
                  } else {
                     ((TextView)findViewById(R.id.Resultat)).setText("Mauvaise réponse donnée: " + hello);    
                     ((TextView)findViewById(R.id.Resultat2)).setText("Reponse attendue: " + verbe);                    
                     Toast.makeText(Test.this,    "Mauvaise réponse :(", Toast.LENGTH_LONG).show();
                     reponsef++;
                  }
                 ((TextView)findViewById(R.id.resultatb)).setText("Nombre de bonne reponse: " + reponseb);                    
                 ((TextView)findViewById(R.id.resultatf)).setText("Nombre de mauvaise reponse: " + reponsef);                    
                 }
           }

       );


       //---update title---
       db.open();
       if (db.updateTitle(1, 
               reponseb, 
               reponsef))
           Toast.makeText(this, "Update successful.", 
               Toast.LENGTH_LONG).show();
       else
           Toast.makeText(this, "Update failed.", 
               Toast.LENGTH_LONG).show();
       //-------------------*/

   }

   }


stats

package fr.tecknologiks.testanglais;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.Toast;

public class Stats extends Activity {
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.stats);
       DBAdapter db = new DBAdapter(this);
       //---get all titles---
       db.open();
       Cursor c = db.getAllTitles();
       if (c.moveToFirst())
       {
           do {          
               DisplayTitle(c);
           } while (c.moveToNext());
       }
       db.close();
}
   public void DisplayTitle(Cursor c)
   {
       Toast.makeText(this, 
               "id: " + c.getString(0) + "\n" +
               "ISBN: " + c.getString(1) + "\n" +
               "TITLE: " + c.getString(2) + "\n" + c.getString(3),
               Toast.LENGTH_LONG).show();        
   } 
}

update 1: j'ai oublier le logcat dsl

10-24 00:48:17.892: WARN/ActivityManager(165): Activity destroy timeout for HistoryRecord{46c32ed0 fr.tecknologiks.testanglais/.Onglets}
10-24 00:49:08.982: ERROR/Tethering(165): active iface (usb0) reported as added, ignoring
10-24 00:51:02.042: ERROR/lights(165): write ok string=1,len=1
10-24 00:51:02.042: ERROR/lights(165): write ok string=0,len=1
10-24 00:51:02.042: ERROR/lights(165): write ok string=0 0,len=3
10-24 00:51:02.042: ERROR/lights(165): write ok string=0,len=1
10-24 00:51:02.052: ERROR/lights(165): write ok string=0,len=1
10-24 00:51:02.052: ERROR/lights(165): write ok string=0 0,len=3
10-24 00:53:26.592: ERROR/Tethering(165): active iface (usb0) reported as added, ignoring
10-24 00:55:22.522: ERROR/Tethering(165): active iface (usb0) reported as added, ignoring
10-24 00:57:41.082: WARN/InputManagerService(165): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@46df6710
10-24 00:57:41.942: ERROR/Database(4949): Failure 1 (near " ": syntax error) on 0x257cf8 when preparing 'create table titles (_id integer primary key autoincrement, '.
10-24 00:57:41.942: WARN/dalvikvm(4949): threadid=1: thread exiting with uncaught exception (group=0x40025a08)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949): FATAL EXCEPTION: main
10-24 00:57:41.952: ERROR/AndroidRuntime(4949): java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.tecknologiks.testanglais/fr.tecknologiks.testanglais.Onglets}: java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.tecknologiks.testanglais/fr.tecknologiks.testanglais.Test}: android.database.sqlite.SQLiteException: near " ": syntax error: create table titles (_id integer primary key autoincrement, 
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.os.Looper.loop(Looper.java:144)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.main(ActivityThread.java:4937)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at java.lang.reflect.Method.invokeNative(Native Method)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at java.lang.reflect.Method.invoke(Method.java:521)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at dalvik.system.NativeStart.main(Native Method)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.tecknologiks.testanglais/fr.tecknologiks.testanglais.Test}: android.database.sqlite.SQLiteException: near " ": syntax error: create table titles (_id integer primary key autoincrement, 
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2627)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.widget.TabHost.addTab(TabHost.java:213)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at fr.tecknologiks.testanglais.Onglets.onCreate(Onglets.java:19)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     ... 11 more
10-24 00:57:41.952: ERROR/AndroidRuntime(4949): Caused by: android.database.sqlite.SQLiteException: near " ": syntax error: create table titles (_id integer primary key autoincrement, 
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1817)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at fr.tecknologiks.testanglais.DBAdapter$DatabaseHelper.onCreate(DBAdapter.java:48)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at fr.tecknologiks.testanglais.DBAdapter.open(DBAdapter.java:66)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at fr.tecknologiks.testanglais.Test.onCreate(Test.java:330)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
10-24 00:57:41.952: ERROR/AndroidRuntime(4949):     ... 20 more

Lien vers le commentaire
Partager sur d’autres sites

Y'a écrit dans le log cat que le bug est une erreur de syntaxe SQL lorsque tu crées ta table :

java.lang.RuntimeException: Unable to start activity ComponentInfo{fr.tecknologiks.testanglais/fr.tecknologiks.testanglais.Test}: android.database.sqlite.SQLiteException: near " ": syntax error: create table titles (_id integer primary key autoincrement,

Par contre, j'ai pas trouvé le create table dans ton code !!

Emmanuel / Alocaly

Lien vers le commentaire
Partager sur d’autres sites

Salut,

Dans ta classe DBAdapter, t'as une chaine de caractères qui est incomplète et qu'apparemment tu executes de manière incomplète.

En effet, si tu regardes DATABASE_CREATE, tu l'initialises ainsi

"create table titles (_id integer primary key autoincrement, ";

Or, tu complètes pas ta requête SQL et je pense que quand tu fais appel à

db.execSQL(DATABASE_CREATE);

Ca bug tout simplement...

Lien vers le commentaire
Partager sur d’autres sites

Oui effectivement, mais il était 3 heures du mat ( je voulais publier une nouvelle version de mon appli :) ), et j'avais pas les yeux en face des trous.

Toujours est-t-il que c'est ca qui ne va pas, comme te l'a dit Dimach :

"create table titles (_id integer primary key autoincrement, ";

Ce n'est pas une requete SQL correcte, il y a une parenthese que tu ne fermes pas !( et sinon, ca me surprend qu'il y ait qu'un ID dans ta base )

Emmanuel/ Alocaly

Lien vers le commentaire
Partager sur d’autres sites

Ah ok ... merci... l id je sais pas ce qu'il fait la... un simple code de.tuto... quand j aurai reçu mon livre je ferai mon propre code...je teste ça ce soir...

update : ca ne marche pas... enfin ca marche mais je peut updater la base que quand l'apply se lance...

quand je le met ici ca bug...

 button.setOnClickListener(
           new OnClickListener() {
           @Override
           public void onClick(View v) {
               //on réupère le texte écrit dans l'EditText
               hello = editText.getText().toString();

                 if (hello.equals(verbe)){
                     ((TextView)findViewById(R.id.Resultat)).setText("Bonne réponse");                    
                     ((TextView)findViewById(R.id.Resultat2)).setText("Réponse: " + hello);                    
                     Toast.makeText(Test.this,    "Bonne réponse ! :)", Toast.LENGTH_LONG).show();
                     reponseb++;
                 } else {
                     ((TextView)findViewById(R.id.Resultat)).setText("Mauvaise réponse donnée: " + hello);    
                     ((TextView)findViewById(R.id.Resultat2)).setText("Reponse attendue: " + verbe);                    
                     Toast.makeText(Test.this,    "Mauvaise réponse :(", Toast.LENGTH_LONG).show();
                     reponsef++;
                  }
                 ((TextView)findViewById(R.id.resultatb)).setText("Nombre de bonne reponse: " + reponseb);                    
                   ((TextView)findViewById(R.id.resultatf)).setText("Nombre de mauvaise reponse: " + reponsef);                    

                    DBAdapter db = new DBAdapter(this);    
                       db.open();        
                       long id;
                       id = db.insertTitle(
                               "0",
                               "0"); 
                   //---update title---

                   db.open();
                   if (db.updateTitle(1, 
                           reponseb, 
                           reponsef))

                   //-------------------*/
                    db.close();
                 }
           }

       );

log cat

10-25 00:20:30.068: ERROR/Tethering(165): active iface (usb0) reported as added, ignoring
10-25 00:22:17.658: ERROR/AndroidRuntime(4205): FATAL EXCEPTION: main
10-25 00:22:17.658: ERROR/AndroidRuntime(4205): java.lang.ClassCastException: fr.tecknologiks.testanglais.Test$2
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at fr.tecknologiks.testanglais.DBAdapter$DatabaseHelper.(DBAdapter.java:44)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at fr.tecknologiks.testanglais.DBAdapter.(DBAdapter.java:37)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at fr.tecknologiks.testanglais.Test$2.onClick(Test.java:322)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.view.View.performClick(View.java:2408)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.view.View$PerformClick.run(View.java:8817)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.os.Handler.handleCallback(Handler.java:587)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.os.Looper.loop(Looper.java:144)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at android.app.ActivityThread.main(ActivityThread.java:4937)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at java.lang.reflect.Method.invokeNative(Native Method)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at java.lang.reflect.Method.invoke(Method.java:521)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-25 00:22:17.658: ERROR/AndroidRuntime(4205):     at dalvik.system.NativeStart.main(Native Method)

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...