Bonjour a tous,
J’ai un problème sur android studio, Je voudrais que quand on clique sur le bouton de la première activity cela m’envoie sur ma deuxième activity .
J’ai un message d’erreur et je n’arrive pas a trouver d’où sa viens.
Je vais vous envoyer mon code.
Merci beaucoup de votre réponse,
Cordialement,
Ci-dessous le code accueil.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fond"
tools:ignore="DuplicateIds">
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/la"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="90dp"
android:layout_marginEnd="90dp"
android:layout_marginBottom="193dp"
android:text="Connexion" />
</RelativeLayout>
Ci-dessous le code activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/capture"
tools:context="MainActivity">
<TextView
android:id="@+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connexion"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.17000002"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/nomdutilisateur"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="32dp"
android:layout_marginRight="32dp"
android:drawableLeft="@android:drawable/ic_menu_myplaces"
android:ems="10"
android:hint="Nom d'utilisateur"
android:inputType="textPersonName"
android:textColorHint="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/nom" />
<EditText
android:id="@+id/editTextTextPersonName2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:drawableLeft="@android:drawable/ic_lock_idle_lock"
android:ems="10"
android:hint="******"
android:inputType="textPersonName"
android:password="true"
android:textColorHint="@color/white"
app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonName4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName4"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName4" />
<EditText
android:id="@+id/editTextTextPersonName3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:drawableLeft="@android:drawable/sym_action_email"
android:ems="10"
android:hint="Email"
android:inputType="textPersonName"
android:textColorHint="@color/white"
app:layout_constraintBottom_toTopOf="@+id/editTextTextPersonName4"
app:layout_constraintEnd_toEndOf="@+id/nomdutilisateur"
app:layout_constraintStart_toStartOf="@+id/nomdutilisateur"
app:layout_constraintTop_toBottomOf="@+id/nomdutilisateur" />
<EditText
android:id="@+id/editTextTextPersonName4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:drawableLeft="@android:drawable/ic_lock_idle_lock"
android:ems="10"
android:hint="******"
android:inputType="textPersonName"
android:password="true"
android:textColorHint="@color/white"
app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonName3"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName3"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName3" />
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Confirmer"
app:layout_constraintEnd_toEndOf="@+id/editTextTextPersonName2"
app:layout_constraintStart_toStartOf="@+id/editTextTextPersonName2"
app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName2" />
</androidx.constraintlayout.widget.ConstraintLayout>
et ci-dessous le code MainActivity.java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accueil);
button = (Button) findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openaccueil();
}
});
}
public void openaccueil() {
Intent intent = new Intent(this, accueilactivity.class);
startActivity(intent);
}
}
Merci pour votre aide et de votre temps