Java 为什么我的应用程序在点击任何按钮时崩溃?
我正在尝试使用intents,但单击任何按钮时,应用程序停止工作并终止。我是初学者,无法找到原因。我正在提供我的xml文件、java文件和menifest文件。请有人帮助。 这是我的xml文件:Java 为什么我的应用程序在点击任何按钮时崩溃?,java,android,Java,Android,我正在尝试使用intents,但单击任何按钮时,应用程序停止工作并终止。我是初学者,无法找到原因。我正在提供我的xml文件、java文件和menifest文件。请有人帮助。 这是我的xml文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://s
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
tools:context="com.example.shreya.intents.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Set Alarm"
android:id="@+id/alarm"
android:onClick="setAlarm"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Map"
android:id="@+id/map"
android:onClick="seeMap"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Mail"
android:id="@+id/mail"
android:onClick="email"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID"
android:inputType="textCapWords"
android:id="@+id/address"/>
</LinearLayout>
最后这是我的menifest文件:
<?xml version="1.0" encoding="utf-8"?>
您必须将参数
视图添加到onClick
方法中
例如:
public void setAlarm(View view){
}
将该参数添加到其他onClick
方法中:email
和seeMap
在引擎盖下,系统使用反射来找出活动
中确切的onClick
方法,并且系统使用以下确切模式来查找该方法:在xmlonClick
属性中具有指定方法名称的public void
方法,并且具有单个参数视图
请提供碰撞的stacktrace/logcat
<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>
public void setAlarm(View view){
}