ボタンをクリックするとログを記録するAndroidアプリケーションを作成しようとしていますが、コンソールにテキストを挿入しますが、コンパイルして実行するとエラーが表示されます私のギャラクシーS7エッジで7.0 APIバージョン24を実行中。java.lang.RuntimeException:activitをインスタンス化できません
I've read that I need to add something into the manifest fileしかし、私は何を追加する必要があるのか分かりません。
致命的な例外:メイン プロセス:me.adamstephenson.test.test1、PID:16405 java.lang.RuntimeException:インスタンス化することができない活性ComponentInfo {me.adamstephenson.test.test1/me.adamstephenson.test .test1.MainActivity}:java.lang.ClassCastExceptionが:me.adamstephenson.test.test1.MainActivityは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");
}
});
}
}
}
にキャストすることはできません
はここで最後にここにレイアウト
<?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>
であるあなたは、あなたのマニフェストに間違ったクラスを参照しているマニフェストファイル
<?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>
がマニフェスト –
@NikaKurdadze確かに示してください、ちょうど記事を編集した:あなたはそれをこの適切な方法を使用することができますが、私はあなたがこの方法を選んだ理由を任意のアイデアを持っていません。 – Adam