IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Application qui crash 9 fois sur 10 et je ne comprends pas pourquoi


Sujet :

Android

  1. #1
    Membre averti
    Inscrit en
    Février 2011
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 27
    Par défaut Application qui crash 9 fois sur 10 et je ne comprends pas pourquoi
    bonsoir a tous quelqu'un pourrais m'aider a comprendre pourquoi mon application marche sur l'emulateur mais une fois transféré sur le tel elle crash 9 fois sur 10
    Help Svp pcq je seche
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
     
    package com.example.e;
     
    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapPrimitive;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.HttpTransportSE;
    import android.app.Activity;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.preference.PreferenceManager;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Spinner;
    import android.widget.TextView;
     
     
    public class MainActivity extends Activity {
     
    	EditText user,pass;
    	Button connection;
    	TextView inscription,result ;
    	public Spinner spinner;
     
    	private final String NAMESPACE = "http://ws.userlogin.com";
        private final String URL = "http://192.168.1.4:8085/Login/services/Login?wsdl";
        private final String SOAP_ACTION = "http://ws.userlogin.com/authentication";
        private final String METHOD_NAME = "authentication";
     
     
        private final String SOAP_ACTION1 = "http://ws.userlogin.com/authentification";
        private final String METHOD_NAME1 = "authentification";
        String spin1,str;
     
     
    	@Override
    		protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
     
    		setContentView(R.layout.activity_main);
    		spinner=(Spinner)findViewById(R.id.spin);
     
    		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.Type,android.R.layout.simple_spinner_item);
    		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    		spinner.setAdapter(adapter);
    		spin1 = spinner.getSelectedItem().toString();
    		result = (TextView) findViewById(R.id.Cat);
    		connection=(Button)findViewById(R.id.Connect);
    		inscription=(TextView)findViewById(R.id.Inscription);
    		inscription.setOnClickListener(new OnClickListener() {
     
    			@Override
    			public void onClick(View v) {
    				Intent i=new Intent(MainActivity.this,Inscription.class);
    			startActivity(i);	
     
    			}
    		});
     
    		connection.setOnClickListener(new OnClickListener() {
     
    			@Override
    			public void onClick(View v) {
    				spin1 = spinner.getSelectedItem().toString();
    				if (spin1.equals("Vendeur")){		
     
    					loginAction();
    					SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    	                SharedPreferences.Editor editor = app_preferences.edit();
    	                String nomu = user.getText().toString();
    	                editor.putString("NomV", nomu);
    	                editor.commit();
     
     
    		  }
    			else if(spin1.equals("Client")){
     
    					loginAction1();
     
     
    			}
     
     
     
       }
      });
        }
     
     
        private void loginAction() {
     
        	new Thread(new Runnable() {
     
    			@Override
    			public void run() {
    				 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
     
    				 	user=(EditText)findViewById(R.id.use_er);
    					String u=user.getText().toString();
    					pass=(EditText)findViewById(R.id.Pass);
     
    					String p=pass.getText().toString();
    			      //Pass value for userName variable of the web service
    			        PropertyInfo unameProp =new PropertyInfo();
    			        unameProp.setName("userName");//Define the variable name in the web service method
    			        unameProp.setValue(u);//set value for userName variable
    			        unameProp.setType(String.class);//Define the type of the variable
    			        request.addProperty(unameProp);//Pass properties to the variable
     
    			      //Pass value for Password variable of the web service
    			        PropertyInfo passwordProp =new PropertyInfo();
    			        passwordProp.setName("password");
    			        passwordProp.setValue(p);
    			        passwordProp.setType(String.class);
    			        request.addProperty(passwordProp);
     
    			        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    			        envelope.setOutputSoapObject(request);
    			        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
     
    			        try{
    			            androidHttpTransport.call(SOAP_ACTION, envelope);
    			               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    			            str=response.toString(); 
     
     
    			        }
    			        catch(Exception e){
     
    			        }
    			        runOnUiThread(new Runnable(){
    			        	public void run(){
    			        		result = (TextView) findViewById(R.id.Cat);
    				               result.setText(str);
    				               if (result.getText().equals("Authentification Reussi, Bienvenue Chere Vendeur !")){
    									Intent j=new Intent(MainActivity.this,Accueil_Vendeur.class);
    									startActivity(j); 
    									finish();
    					                }
     
    			        	}
    			        });
     
    			}
     
     
    		}).start();
     
     
    }
     
        private void loginAction1() {
     
        	new Thread(new Runnable() {
     
    			@Override
    			public void run() {
    				 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
     
    			     user=(EditText)findViewById(R.id.use_er);
    					String u=user.getText().toString();
    					pass=(EditText)findViewById(R.id.Pass);
     
    					String p=pass.getText().toString();
    			      //Pass value for userName variable of the web service
    			        PropertyInfo unameProp =new PropertyInfo();
    			        unameProp.setName("userName");//Define the variable name in the web service method
    			        unameProp.setValue(u);//set value for userName variable
    			        unameProp.setType(String.class);//Define the type of the variable
    			        request.addProperty(unameProp);//Pass properties to the variable
     
    			      //Pass value for Password variable of the web service
    			        PropertyInfo passwordProp =new PropertyInfo();
    			        passwordProp.setName("password");
    			        passwordProp.setValue(p);
    			        passwordProp.setType(String.class);
    			        request.addProperty(passwordProp);
     
    			        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    			        envelope.setOutputSoapObject(request);
    			        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
     
    			        try{
    			            androidHttpTransport.call(SOAP_ACTION1, envelope);
    			               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
    			            str=response.toString();
     
     
     
    			        }
    			        catch(Exception e){
     
    			        }
    			        runOnUiThread(new Runnable(){
    			        	public void run(){
    			        		result = (TextView) findViewById(R.id.Cat);
    				               result.setText(str);
    				           	if (result.getText().toString().equals("Authentification Reussi, Bienvenue Chere Client !")){
    								Intent j=new Intent(MainActivity.this,Accueil.class);
    								startActivity(j);
    								finish();
    								}
    			        	}
    			        });
     
    			}
     
     
    		}).start();
     
     
    }
    }
    les erreurs affiché sont cella :
    04-15 23:38:02.265: W/dalvikvm(16873): threadid=1: thread exiting with uncaught exception (group=0x40018578)
    04-15 23:38:02.273: E/AndroidRuntime(16873): FATAL EXCEPTION: main
    04-15 23:38:02.273: E/AndroidRuntime(16873): java.lang.NullPointerException
    04-15 23:38:02.273: E/AndroidRuntime(16873): at com.example.e.MainActivity$2.onClick(MainActivity.java:75)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.view.View.performClick(View.java:2485)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.view.View$PerformClick.run(View.java:9080)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.os.Handler.handleCallback(Handler.java:587)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.os.Handler.dispatchMessage(Handler.java:92)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.os.Looper.loop(Looper.java:130)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at android.app.ActivityThread.main(ActivityThread.java:3687)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at java.lang.reflect.Method.invokeNative(Native Method)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at java.lang.reflect.Method.invoke(Method.java:507)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    04-15 23:38:02.273: E/AndroidRuntime(16873): at dalvik.system.NativeStart.main(Native Method)

  2. #2
    Membre émérite
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    757
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2011
    Messages : 757
    Par défaut
    L'erreur provient de la ligne 75 de ton MainActivity où le système rencontre une erreur due à un pointeur null.
    Peux-tu nous dire exactement ce qu'il y a à cette ligne ?

  3. #3
    Membre très actif
    Homme Profil pro
    Ingénieur Informatique et Développeur Android
    Inscrit en
    Janvier 2010
    Messages
    384
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Ingénieur Informatique et Développeur Android

    Informations forums :
    Inscription : Janvier 2010
    Messages : 384
    Par défaut
    Citation Envoyé par nacimovitch Voir le message
    SharedPreferences app_preferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    SharedPreferences.Editor editor = app_preferences.edit();
    Bonjour, je pense que vous avez un erreur dans app_preferences que est null lorsque tu appele le méthode .edit().

    Essaye de remplacer ce code par le suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    SharedPreferences app_preferences = this.getSharedPreferences("MyPrefsFile", MODE_WORLD_READABLE);
    SharedPreferences.Editor editor = app_preferences.edit();

    Bon chance

Discussions similaires

  1. getElementById qui retourne "" une fois sur deux
    Par Cronycs dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 02/05/2007, 17h33
  2. Requête qui fonctionne 1 fois sur 100
    Par nicotine002 dans le forum Langage
    Réponses: 1
    Dernier message: 05/08/2006, 11h42
  3. Erreur ASP : le test qui marche une fois sur 2 !
    Par Ryo_san dans le forum ASP
    Réponses: 2
    Dernier message: 04/07/2006, 09h47
  4. Requete sur une table qui pointe 2 fois sur une autre
    Par Satch dans le forum Langage SQL
    Réponses: 1
    Dernier message: 10/01/2006, 08h48
  5. Pb : malloc qui marche une fois sur deux .... ?
    Par guillaume_pfr dans le forum C
    Réponses: 14
    Dernier message: 21/07/2003, 09h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo