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

API standards et tierces Android Discussion :

Problème Socket Android


Sujet :

API standards et tierces Android

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité
    Invité(e)
    Par défaut Problème Socket Android
    Bonjour,



    Je développe actuellement une application android avec des sockets et quand je la lance elle s'arrête.Cette application permet d'envoyer des commandes d'une Nexus 7 sous Android KitKat vers un boitier domotique (IPX 800) via le protocole M2M. L'application fonctionne très bien sous Android 2.2 mais pas sur 4.4.2.



    Voici le logCat qd je lance l'application :

    01-30 07:25:06.183: W/dalvikvm(995): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
    01-30 07:25:06.273: E/AndroidRuntime(995): FATAL EXCEPTION: main
    01-30 07:25:06.273: E/AndroidRuntime(995): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.domotique/com.android.domotique.Admin}: java.lang.NullPointerException
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.access$600(ActivityThread.java:141)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.os.Handler.dispatchMessage(Handler.java:99)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.os.Looper.loop(Looper.java:137)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.main(ActivityThread.java:5041)
    01-30 07:25:06.273: E/AndroidRuntime(995): at java.lang.reflect.Method.invokeNative(Native Method)
    01-30 07:25:06.273: E/AndroidRuntime(995): at java.lang.reflect.Method.invoke(Method.java:511)
    01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    01-30 07:25:06.273: E/AndroidRuntime(995): at dalvik.system.NativeStart.main(Native Method)
    01-30 07:25:06.273: E/AndroidRuntime(995): Caused by: java.lang.NullPointerException
    01-30 07:25:06.273: E/AndroidRuntime(995): at com.android.domotique.Admin.onCreate(Admin.java:117)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.Activity.performCreate(Activity.java:5104)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    01-30 07:25:06.273: E/AndroidRuntime(995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    01-30 07:25:06.273: E/AndroidRuntime(995): ... 11 more




    voici le code java de mon application :



    Code Java : 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
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    package com.android.domotique;
     
     
    import java.io.BufferedReader;
     
    import java.io.BufferedWriter;
     
    import java.io.IOException;
     
    import java.io.InputStreamReader;
     
    import java.io.OutputStreamWriter;
     
    import java.io.PrintWriter;
     
    import java.net.Inet4Address;
     
    import java.net.InetAddress;
     
    import java.net.Socket;
     
    import java.net.UnknownHostException;
     
     
    import android.os.Bundle;
     
    import android.view.View;
     
    import android.widget.Button;
     
    import android.widget.ToggleButton;
     
     
    public class Admin extends MainActivity {
     
     
        private Button bPrecedent;
     
        private Button bSuivant;
     
        private ToggleButton Relai1;//Eclairage 1
     
        private ToggleButton Relai2;//Eclairage Ext
     
        private ToggleButton Relai3;//Eclairage Degagement
     
        private ToggleButton Relai4;//Portail
     
     
        String AdresseIP = "10.129.101.193";
     
        int Port = 9870;
     
        Socket SocketIPX;
     
        PrintWriter BuffW;
     
        BufferedReader BuffR;
     
     
        @Override
     
        protected void onCreate(Bundle savedInstanceState) {
     
            super.onCreate(savedInstanceState);
     
     
            bPrecedent = new Button(this);
     
            Relai1 = new ToggleButton(this);
     
            Relai2 = new ToggleButton(this);
     
            Relai3 = new ToggleButton(this);
     
            Relai4 = new ToggleButton(this);
     
     
            setContentView(R.layout.admin);
     
     
            bPrecedent = (Button) findViewById(R.id.Buttonpre);
     
            Relai1 = (ToggleButton) findViewById(R.id.toggleButton1);
     
            Relai2 = (ToggleButton) findViewById(R.id.toggleButton2);
     
            Relai3 = (ToggleButton) findViewById(R.id.toggleButton3);
     
            Relai4 = (ToggleButton) findViewById(R.id.toggleButton4);
     
     
            bPrecedent.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
                    finish();
     
     
                }
     
            });
     
     
            Relai1.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
                    Thread tTest = new Thread() {
     
                        public void run() {
     
                            if (Relai1.isChecked())
     
                                CommunicationIPX("Set11");
     
                            else
     
                                CommunicationIPX("Set10");
     
                        }
     
                    };
     
                    tTest.start();
     
     
                }
     
            });
     
     
            Relai2.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
                    if (Relai2.isChecked())
     
                        CommunicationIPX("Set21");
     
                    else
     
                        CommunicationIPX("Set20");
     
                }
     
            });
     
     
            Relai3.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
                    if (Relai3.isChecked())
     
                        CommunicationIPX("Set31");
     
                    else
     
                        CommunicationIPX("Set30");
     
                }
     
            });
     
     
            Relai4.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
                    if (Relai1.isChecked())
     
                        CommunicationIPX("Set41");
     
                    else
     
                        CommunicationIPX("Set40");
     
                }
     
            });
     
     
            bSuivant.setOnClickListener(new View.OnClickListener() {
     
     
                @Override
     
                public void onClick(View v) {
     
    // TODO Auto-generated method stub
     
     
                }
     
            });
     
     
            try {
     
                InetAddress serverAddr = Inet4Address.getByName(AdresseIP);
     
                SocketIPX = new Socket(serverAddr, Port);
     
            } catch (UnknownHostException e1) {
     
                e1.printStackTrace();
     
            } catch (IOException e1) {
     
                e1.printStackTrace();
     
            }
     
     
            //ouverture du buffeur pour envoyer dans le socket qu'on vient de créer
     
            try {
     
                BuffW = new PrintWriter(new BufferedWriter(new OutputStreamWriter(SocketIPX.getOutputStream())), true);
     
            } catch (IOException e) {
     
                // TODO Auto-generated catch block
     
                e.printStackTrace();
     
            }
     
     
            //idem pour recevoir
     
            try {
     
                BuffR = new BufferedReader(new InputStreamReader(SocketIPX.getInputStream()));
     
            } catch (IOException e) {
     
                // TODO Auto-generated catch block
     
                e.printStackTrace();
     
            }
     
     
        }
     
        public String CommunicationIPX(String Ordre) {
     
     
            String sClientMsg = "";
     
     
            //envoie l'ordre passé en argument de la fonction en l'état (si c'est un truc qui n'existe pas, l'IPX nous le dira)
     
            BuffW.println(Ordre);
     
            BuffW.flush();
     
     
            //lire la réponse
     
            try {
     
                sClientMsg = BuffR.readLine();
     
            } catch (IOException e) {
     
                // TODO Auto-generated catch block
     
                e.printStackTrace();
     
            }
     
     
            //return la réponse de l'IPX
     
            return sClientMsg;
     
        }//fin Communication IPX
     
     
    }
    Dernière modification par Hizin ; 30/01/2014 à 09h46. Motif: Merci d'utiliser la balise [code] (#) + indentation du code.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème socket Android
    Par hannibal813 dans le forum API standards et tierces
    Réponses: 1
    Dernier message: 05/04/2013, 01h28
  2. Problème Socket
    Par karl2mil1 dans le forum C++Builder
    Réponses: 3
    Dernier message: 12/09/2005, 23h35
  3. Problème socket raw ? bizarre :~
    Par MonsieurAk dans le forum Windows
    Réponses: 2
    Dernier message: 12/07/2005, 14h12
  4. [MFC] Problème Socket + Connexion SQL
    Par BananaUltra3C dans le forum MFC
    Réponses: 6
    Dernier message: 20/05/2005, 16h41
  5. [Réseau] Problème socket
    Par neenee dans le forum Entrée/Sortie
    Réponses: 14
    Dernier message: 18/01/2005, 15h26

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