J'essaie d'écrire une application Android qui se connecte lorsque vous cliquez sur un bouton pour mettre du texte dans la console, mais je reçois une erreur lorsque je la remplis et l'exécute sur mon bord Galaxy S7 exécutant 7.0 API version 24.java.lang.RuntimeException: Impossible d'instancier l'activité
I've read that I need to add something into the manifest file Cependant, je ne suis pas sûr de ce que j'ai besoin d'ajouter.
EXCEPTION FATAL: principal processus: me.adamstephenson.test.test1, PID: 16405 java.lang.RuntimeException: impossible à instancier activité ComposantInfo {me.adamstephenson.test.test1/me.adamstephenson.test .test1.MainActivity}: java.lang.ClassCastException: me.adamstephenson.test.test1.MainActivity ne peut pas être jeté à android.app.Activity
package me.adamstephenson.test.test1;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity {
public class MyActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.RequestKey);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("RequestKey", "Clicked");
}
});
}
}
}
Voici la mise en page
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="me.adamstephenson.test.test1.MainActivity">
<Button
android:id="@+id/RequestKey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="196dp"
tools:layout_editor_absoluteY="129dp" />
</android.support.constraint.ConstraintLayout>
est enfin là le fichier manifeste
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.adamstephenson.test.test1">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
S'il vous plaît montrer votre –
manifeste @NikaKurdadze Bien sûr, vient de modifier le poste. – Adam