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 :

NullPointerException sur setText


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Développeur android & Java Web application
    Inscrit en
    Avril 2016
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur android & Java Web application
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 105
    Points : 59
    Points
    59
    Par défaut NullPointerException sur setText
    Bonjour la famille


    J'essaie de récupérer des informations et afficher dans un TextView a l'exécution de l'application, l'application se plante et me met ca

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
    Voici Mon Layout :

    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
    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
    309
    310
    311
     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:background="#000"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
     
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true">
     
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
     
                <LinearLayout
                    android:layout_weight="3"
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
     
                    <TextView
                        android:gravity="center_horizontal|center_vertical"
                        android:textStyle="bold"
                        android:textSize="20dp"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:textColor="@color/colorPrimary"
                        android:text="SOMME DES COMMISSIONS"/>
     
                    <TextView
                        android:id="@+id/commissions"
                        android:gravity="center_horizontal|center_vertical|right"
                        android:textStyle="bold"
                        android:textSize="25dp"
                        android:layout_weight="1"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:textColor="@color/colorPrimary"
                        android:layout_marginRight="8dp"
                        android:text="0"/>
     
                </LinearLayout>
     
                <LinearLayout
                    android:layout_weight="3.8"
                    android:background="@color/colorPrimary"
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
     
                    <TextView
                        android:textStyle="bold"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:textColor="#fff"/>
     
                </LinearLayout>
     
                <LinearLayout
                    android:layout_weight="1"
                    android:background="#9e9e9e"
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Stock de la veille"/>
     
                        <TextView
                            android:id="@+id/veille"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_marginRight="8dp"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#343434"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Stock initial"/>
     
                        <TextView
                            android:id="@+id/initial"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:layout_marginRight="8dp"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#9e9e9e"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Appro OCI"/>
     
                        <TextView
                            android:id="@+id/oci1"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_marginRight="8dp"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#343434"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Appro BOX"/>
     
                        <TextView
                            android:id="@+id/box"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_marginRight="8dp"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#8c8c8c"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Rechargement réel"/>
     
                        <TextView
                            android:id="@+id/reel"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:layout_marginRight="8dp"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#343434"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Stock final"/>
     
                        <TextView
                            android:id="@+id/fin"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_marginRight="8dp"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#8c8c8c"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Commission théorique"/>
     
                        <TextView
                            android:id="@+id/theoriques"
                            android:textStyle="bold"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:layout_marginRight="8dp"
                            android:text="0"/>
     
                    </LinearLayout>
     
                    <LinearLayout
                        android:layout_weight="1"
                        android:background="#343434"
                        android:orientation="horizontal"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
     
                        <TextView
                            android:layout_marginLeft="8dp"
                            android:gravity="left|center_vertical"
                            android:layout_weight="1"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:text="Ecart Comm"/>
     
                        <TextView
                            android:id="@+id/ecart"
                            android:layout_weight="1"
                            android:gravity="right|center_vertical"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:textColor="#fff"
                            android:layout_marginRight="8dp"
                            android:text="0"/>
     
                    </LinearLayout>
     
                </LinearLayout>
     
            </LinearLayout>
     
        </ScrollView>
     
    </LinearLayout>
    Et Ma classe :

    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
    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
     
    private class GetContacts extends AsyncTask<Void, Void, Void> {
     
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Showing progress dialog
                pDialog = new ProgressDialog(MainActivity.this);
                pDialog.setMessage("Veuillez patienter...");
                pDialog.setCancelable(false);
                pDialog.show();
     
            }
     
            @Override
            protected Void doInBackground(Void... arg0) {
     
                final Calendar mcurrentDate=Calendar.getInstance();
                final int mYear = mcurrentDate.get(Calendar.YEAR);
                final int mMonth = mcurrentDate.get(Calendar.MONTH);
                final int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
     
                mcurrentDate.set(mYear, mMonth, mDay);
                String date = dateFormatter.format(mcurrentDate.getTime());
     
                HttpHandler sh = new HttpHandler();
     
                String url = "http://212.73.150.166/api/v1/daily_reports/last_reporting";
     
                // Making a request to url and getting response
                String jsonStr = sh.makeServiceCall(url);
     
                Log.e(TAG, "Response from url: " + jsonStr);
     
                if (jsonStr != null) {
                    try {
                        JSONObject jsonObj = new JSONObject(jsonStr);
     
                        // Getting JSON Object node
                        JSONObject contacts = jsonObj.getJSONObject("json");
     
                        // Phone node is JSON Object
                        JSONObject phone = contacts.getJSONObject("result");
     
                        JSONObject stock_initial = phone.getJSONObject("stock_initial");
     
                        final String stock_initial1 = stock_initial.getString("type_1");
                        final String stock_initial2 = stock_initial.getString("type_2");
                        final String stock_initialb = stock_initial.getString("box");
     
                        Log.e(TAG, "BOX: " + stock_initialb);
     
                        JSONObject appro_oci1 = phone.getJSONObject("appro_oci1");
     
                        final String appro_oci11 = appro_oci1.getString("type_1");
                        final String appro_oci12 = appro_oci1.getString("type_2");
                        final String appro_oci1b = appro_oci1.getString("box");
     
                        JSONObject stock_final = phone.getJSONObject("stock_final");
     
                        final String stock_final1 = stock_final.getString("type_1");
                        final String stock_final2 = stock_final.getString("type_2");
                        final String stock_finalb = stock_final.getString("box");
     
                        JSONObject commissions_theoriques = phone.getJSONObject("commissions_theoriques");
     
                        final String commissions_theoriques1 = commissions_theoriques.getString("type_1");
                        final String commissions_theoriques2 = commissions_theoriques.getString("type_2");
                        final String commissions_theoriquesb = commissions_theoriques.getString("box");
     
                        JSONObject somme_ecart = phone.getJSONObject("somme_ecart");
     
                        final String somme_ecart1 = somme_ecart.getString("type_1");
                        final String somme_ecart2 = somme_ecart.getString("type_2");
                        final String somme_ecartb = somme_ecart.getString("box");
     
                        JSONObject commissions = phone.getJSONObject("somme_commissions");
     
                        final String somme_commissions1 = commissions.getString("type_1");
                        final String somme_commissions2 = commissions.getString("type_2");
                        final String somme_commissionsb = commissions.getString("box");
     
                        JSONObject appro_box = phone.getJSONObject("appro_box");
     
                        final String appro_box1 = appro_box.getString("type_1");
                        final String appro_box2 = appro_box.getString("type_2");
                        final String appro_boxb = appro_box.getString("box");
     
                        JSONObject sf_veille = phone.getJSONObject("sf_veille");
     
                        final String sf_veille1 = sf_veille.getString("type_1");
                        final String sf_veille2 = sf_veille.getString("type_2");
                        final String sf_veilleb = sf_veille.getString("box");
     
                        JSONObject rechargement_reel = phone.getJSONObject("rechargement_reel");
     
                        final String rechargement_reel1 = rechargement_reel.getString("type_1");
                        final String rechargement_reel2 = rechargement_reel.getString("type_2");
                        final String rechargement_reelb = rechargement_reel.getString("box");
     
                        int somme1 = Integer.parseInt(somme_commissions1);
                        int somme2 = Integer.parseInt(somme_commissionsb);
                        int somme3 = Integer.parseInt(somme_commissions2);
     
                        final int somme = somme1 + somme2 + somme3;
     
                        int initial1 = Integer.parseInt(stock_initial1);
                        int initial2 = Integer.parseInt(stock_initialb);
                        int initial3 = Integer.parseInt(stock_initial2);
     
                        final int initial = initial1 + initial2 + initial3;
     
                        int appro1 = Integer.parseInt(appro_oci11);
                        int appro2 = Integer.parseInt(appro_oci1b);
                        int appro3 = Integer.parseInt(appro_oci12);
     
                        final int appro = appro1 + appro2 + appro3;
     
                        int final1 = Integer.parseInt(stock_final1);
                        int final2 = Integer.parseInt(stock_finalb);
                        int final3 = Integer.parseInt(stock_final2);
     
                        final int fina = final1 + final2 + final3;
     
                        int theo1 = Integer.parseInt(commissions_theoriques1);
                        int theo2 = Integer.parseInt(commissions_theoriquesb);
                        int theo3 = Integer.parseInt(commissions_theoriques2);
     
                        final int theo = theo1 + theo2 + theo3;
     
                        int ecart1 = Integer.parseInt(somme_ecart1);
                        int ecart2 = Integer.parseInt(somme_ecartb);
                        int ecart3 = Integer.parseInt(somme_ecart2);
     
                        final int ecart = ecart1 + ecart2 + ecart3;
     
                        int appbox1 = Integer.parseInt(appro_box1);
                        int appbox2 = Integer.parseInt(appro_boxb);
                        int appbox3 = Integer.parseInt(appro_box2);
     
                        final int appbox = appbox1 + appbox2 + appbox3;
     
                        int recha1 = Integer.parseInt(rechargement_reel1);
                        int recha2 = Integer.parseInt(rechargement_reelb);
                        int recha3 = Integer.parseInt(rechargement_reel2);
     
                        final int recha = recha1 + recha2 + recha3;
     
                        int sf1 = Integer.parseInt(sf_veille1);
                        int sf2 = Integer.parseInt(sf_veilleb);
                        int sf3 = Integer.parseInt(sf_veille2);
     
                        final int sf = sf1 + sf2 + sf3;
     
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
     
                                somm.setText(""+somme);
     
                                somm2 = (TextView) findViewById(R.id.somme_commissions2);
                                initia2 = (TextView) findViewById(R.id.stock_initial2);
                                appr2 = (TextView) findViewById(R.id.appro_oci12);
                                fin2 = (TextView) findViewById(R.id.stock_final2);
                                theoriqu2 = (TextView) findViewById(R.id.commissions_theoriques2);
                                ecar2 = (TextView) findViewById(R.id.somme_ecart2);
                                approbox2 = (TextView) findViewById(R.id.appro_box2);
                                net2 = (TextView) findViewById(R.id.rechargement_reel2);
                                veille2 = (TextView) findViewById(R.id.sf_veille2);
     
                                sommb = (TextView) findViewById(R.id.somme_commissionsb);
                                initiab = (TextView) findViewById(R.id.stock_initialb);
                                apprb = (TextView) findViewById(R.id.appro_oci1b);
                                finb = (TextView) findViewById(R.id.stock_finalb);
                                theoriqub = (TextView) findViewById(R.id.commissions_theoriquesb);
                                ecarb = (TextView) findViewById(R.id.somme_ecartb);
                                approboxb = (TextView) findViewById(R.id.appro_boxb);
                                netb = (TextView) findViewById(R.id.rechargement_reelb);
                                veilleb = (TextView) findViewById(R.id.sf_veilleb);
     
                                somm1 = (TextView) findViewById(R.id.commissions);
                                initia1 = (TextView) findViewById(R.id.initial);
                                appr1 = (TextView) findViewById(R.id.oci1);
                                fin1 = (TextView) findViewById(R.id.fin);
                                theoriqu1 = (TextView) findViewById(R.id.theoriques);
                                ecar1 = (TextView) findViewById(R.id.ecart);
                                approbox1 = (TextView) findViewById(R.id.box);
                                net1 = (TextView) findViewById(R.id.reel);
                                veille1 = (TextView) findViewById(R.id.veille);
     
                                initiat = (TextView) findViewById(R.id.stock_initialt);
                                apprt = (TextView) findViewById(R.id.appro_oci1t);
                                fint = (TextView) findViewById(R.id.stock_finalt);
                                theoriqut = (TextView) findViewById(R.id.commissions_theoriquest);
                                ecartt = (TextView) findViewById(R.id.somme_ecartt);
                                approboxt = (TextView) findViewById(R.id.appro_boxt);
                                nett = (TextView) findViewById(R.id.rechargement_reelt);
                                veillet = (TextView) findViewById(R.id.sf_veillet);
     
                                somm2.setText(somme_commissions2);
                                initia2.setText(stock_initial2);
                                appr2.setText(appro_oci12);
                                fin2.setText(stock_final2);
                                theoriqu2.setText(commissions_theoriques2);
                                ecar2.setText(somme_ecart2);
                                approbox2.setText(appro_box2);
                                net2.setText(rechargement_reel2);
                                veille2.setText(sf_veille2);
     
                                sommb.setText(somme_commissionsb);
                                initiab.setText(stock_initialb);
                                apprb.setText(appro_oci1b);
                                finb.setText(stock_finalb);
                                theoriqub.setText(commissions_theoriquesb);
                                ecarb.setText(somme_ecartb);
                                approboxb.setText(appro_boxb);
                                netb.setText(rechargement_reelb);
                                veilleb.setText(sf_veilleb);
     
                                somm1.setText(somme_commissions1);
    //                            initia1.setText(stock_initial1);
    //                            appr1.setText(appro_oci11);
    //                            fin1.setText(stock_final1);
    //                            theoriqu1.setText(commissions_theoriques1);
    //                            ecar1.setText(somme_ecart1);
    //                            approbox1.setText(appro_box1);
    //                            net1.setText(rechargement_reel1);
    //                            veille1.setText(sf_veille1);
    //
    //                            initiat.setText(""+initial);
    //                            apprt.setText(""+appro);
    //                            fint.setText(""+fina);
    //                            theoriqut.setText(""+theo);
    //                            ecartt.setText(""+ecart);
    //                            approboxt.setText(""+appbox);
    //                            nett.setText(""+recha);
    //                            veillet.setText(""+sf);
                            }
                        });
     
                    } catch (final JSONException e) {
                        Log.e(TAG, "Json parsing error: " + e.getMessage());
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getApplicationContext(),
                                        "Json parsing error: " + e.getMessage(),
                                        Toast.LENGTH_LONG)
                                        .show();
                            }
                        });
     
                    }
                } else {
                    Log.e(TAG, "Couldn't get json from server.");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "Couldn't get json from server. Check LogCat for possible errors!",
                                    Toast.LENGTH_LONG)
                                    .show();
                        }
                    });
     
                }
     
                return null;
            }
     
            @Override
            protected void onPostExecute(Void result) {
                super.onPostExecute(result);
                // Dismiss the progress dialog
                if (pDialog.isShowing())
                    pDialog.dismiss();
                /**
                 * Updating parsed JSON data into ListView
                 * */
            }
     
        }

  2. #2
    Membre confirmé
    Avatar de BeeApps
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juillet 2017
    Messages
    86
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 30
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 86
    Points : 615
    Points
    615
    Par défaut
    Salut,

    Tu appelles setText sur un TextView qui est null. C'est à dire un TextView où tu n'as pas fait de findviewbyid avant pour le récupérer.
    Il faudrait nous indiquer la ligne exacte qui plante.

  3. #3
    Membre du Club
    Homme Profil pro
    Développeur android & Java Web application
    Inscrit en
    Avril 2016
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur android & Java Web application
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 105
    Points : 59
    Points
    59
    Par défaut
    Bonjour

    La ligne est 220, j'ai fait son findViewById toujours la meme chose
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TextView somm1 = (TextView) findViewById(R.id.commissions);

  4. #4
    Membre du Club
    Homme Profil pro
    Développeur android & Java Web application
    Inscrit en
    Avril 2016
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur android & Java Web application
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 105
    Points : 59
    Points
    59
    Par défaut
    J'utilise un tabLayout lorsque je veux mettre les données dans mon TextView c'est la qui me sort
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ava.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference

  5. #5
    Modérateur
    Avatar de Hizin
    Homme Profil pro
    Développeur mobile
    Inscrit en
    Février 2010
    Messages
    2 180
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France

    Informations professionnelles :
    Activité : Développeur mobile

    Informations forums :
    Inscription : Février 2010
    Messages : 2 180
    Points : 5 072
    Points
    5 072
    Par défaut
    Pour ta première erreur : c'est l'un de tes 17 setText qui pose problème.
    Tu invoques une méthode sur un objet qui est null, d'où erreur, comme l'a pointé BeeApps.

    Peux-tu, s'il te plaît, mettre l'erreur complète, avec la stacktrace ? Celle-ci indique des informations utiles, notamment la ligne où la NullPointerException (NPE) survient.

    Je pourrai supputer que tu tentes d'utiliser tes objets AVANT que ceux-ci ne soient attribués... mais sans à la stacktrace, je ne peux aller loin (surtout dans une vue avec 54 TextView à priori : je te conseillerai d'apprendre la modularisation).
    C'est Android, PAS Androïd, ou Androïde didiou !
    Le premier est un OS, le second est la mauvaise orthographe du troisième, un mot français désignant un robot à forme humaine.

    Membre du comité contre la phrase "ça marche PAS" en titre et/ou explication de problème.

    N'oubliez pas de consulter les FAQ Android et les cours et tutoriels Android

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Décembre 2009
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2009
    Messages : 141
    Points : 177
    Points
    177
    Par défaut
    le findViewById renvoit null dans le scope de ton appel.

    vu que tu as déclaré ta classe en private j'imagine que c'est une inner class de ton activity.
    tu as fait le setContentView() de ton layout dans celle-ci ? sans le code on ne peut pas savoir.

    juste pour que cela soit plus un peu plus propre, tu peux transférer ton code qui se trouve dans
    le runOnUiThread() dans le onPostExecute().

    cette méthode s’exécute justement dans le UiThread : c'est fait pour ça.

  7. #7
    Membre du Club
    Homme Profil pro
    Développeur android & Java Web application
    Inscrit en
    Avril 2016
    Messages
    105
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Côte d'Ivoire

    Informations professionnelles :
    Activité : Développeur android & Java Web application
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2016
    Messages : 105
    Points : 59
    Points
    59
    Par défaut
    Au faite c'est un SwipView ou il y'a plusieurs vue au lancement de l'application toutes les informations doivent etre charger

    Mais j'ai trouver la solution

    Si tu fais avec le SwipView il trouve pas tous les id des textView

    J'ai utilisé la Tabhost spec pour regler ce probleme merci

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

Discussions similaires

  1. Réponses: 17
    Dernier message: 13/05/2016, 17h31
  2. Probleme erreur java.lang.NullPointerException
    Par Tsukaasa dans le forum Langage
    Réponses: 4
    Dernier message: 25/05/2006, 18h19
  3. Réponses: 8
    Dernier message: 11/05/2006, 19h32
  4. [JDIC]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    Par kedare dans le forum Concurrence et multi-thread
    Réponses: 4
    Dernier message: 06/05/2006, 22h45
  5. java.lang.NullPointerException getparent()
    Par guano dans le forum AWT/Swing
    Réponses: 5
    Dernier message: 17/03/2006, 17h38

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