probleme sur le deploiement de mon application Android

  • Auteur de la discussion leDecolo
  • Date de début
L

leDecolo

Membre
Inscrit
1 Mai 2019
Messages
1
Points
1
#1
Bonjour ici svp j'ai un probleme lors du deploiement de mon code sur l'emulateur dans android studio a chaque fois que je deploie mon code sans faire de traitement, ni ecouteur sur les objets graphiques mon code se deploie sans probleme mais une fois que fais une traitement sur un bouton comme par exemple un setEnable() sur un bouton mon code produit une erreure suivante

Code:
app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.njikidenisgmail.myfirstapp, PID: 3800
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.njikidenisgmail.myfirstapp/com.njikidenisgmail.myfirstapp.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.clearFocus()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.EditText.clearFocus()' on a null object reference
at com.njikidenisgmail.myfirstapp.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
depuis la ma formation est bloquee a cause de xa j'aimerais si possible que vous m'aidez a resoudre ce probleme

voici le code mon code activity_main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=rgb(41, 105, 176)][COLOR=rgb(226, 80, 65)][COLOR=rgb(41, 105, 176)][COLOR=rgb(226, 80, 65)][COLOR=rgb(41, 105, 176)][COLOR=rgb(226, 80, 65)]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android: paddingLeft="@dimen/activity_horizontal_margin"
    android: paddingRight="@dimen/activity_horizontal_margin"
    android: paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.njikidenisgmail.myfirstapp.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/welcome_msg"
        android:id="@+id/welcome_id" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_val"
        android:id="@+id/btn_id"
        android:layout_below="@+id/welcome_id"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/txt_id"
        android:layout_alignBottom="@+id/btn_id"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_toLeftOf="@+id/btn_id"
        android:layout_toStartOf="@+id/btn_id"
        android:text="veuillez entrer votre nombre" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/screen_id"
        android:layout_below="@+id/btn_id"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/btn_id"
        android:layout_alignEnd="@+id/btn_id"
        android:layout_above="@+id/pb_id" />

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pb_id"
        android:max="10"
        android:progress="5"
        android:indeterminate="false"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/screen_id"
        android:layout_alignEnd="@+id/screen_id" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/screen_id2"
        android:layout_below="@+id/pb_id"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/pb_id"
        android:layout_alignEnd="@+id/pb_id" />
</RelativeLayout>
et mon code MainActivity.java

Code:
import android.support.v7.app.AppCompatActivity;[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]
[COLOR=rgb(44, 130, 201)][COLOR=rgb(226, 80, 65)][COLOR=rgb(44, 130, 201)][COLOR=rgb(226, 80, 65)][COLOR=rgb(44, 130, 201)][COLOR=rgb(226, 80, 65)]import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private TextView welcome;
    private EditText inputnb = null;
  //  private Button val;
    private TextView mess;
    private TextView hist;
    private ProgressBar bar;

    [USER=1236887]@override[/USER]
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

       // val = (Button) findViewById(R.id.btn_id);
        inputnb = (EditText) findViewById(R.id.txt_id);
        welcome = (TextView) findViewById(R.id.welcome_id);
        mess = (TextView) findViewById(R.id.screen_id);
        hist = (TextView) findViewById(R.id.screen_id2);
        bar = (ProgressBar) findViewById(R.id.pb_id);
       // val.setEnabled(false);
       // val.setOnClickListener(valListener);
        inputnb.clearFocus();
        init();
        setContentView(R.layout.activity_main);
    }
    private void init() {

    }


    private View.OnClickListener valListener = new View.OnClickListener() {
        [USER=1236887]@override[/USER]
        public void onClick(View v) {
            Log.i("DEBUG","button cliquer");
        }
    };
}
 
Dernière édition par un modérateur:
Dernière édition par un modérateur:

Sujets en relation


Haut Bas