Java 我的应用程序在使用2个意图时保持强制关闭
为什么我的android应用程序在使用2 intent时总是关闭?当我删除其中一个时,这就是工作。特别是如果我删除java文件中的“Reg”按钮。 谢谢 XML文件:Java 我的应用程序在使用2个意图时保持强制关闭,java,android,android-intent,Java,Android,Android Intent,为什么我的android应用程序在使用2 intent时总是关闭?当我删除其中一个时,这就是工作。特别是如果我删除java文件中的“Reg”按钮。 谢谢 XML文件: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.c
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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=".LoginAct">
<TextView
android:id="@+id/daftar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/daftar"
android:textAlignment="center"
android:textColor="@color/Linktext"
android:clickable="true"
android:focusable="true"
android:layout_marginTop="10dp">
</TextView>
<Button
android:id="@+id/pass"
android:layout_width="wrap_content"
android:layout_height="23dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:background="@color/colorPrimaryDark"
android:clickable="true"
android:focusable="true"
android:text="@string/lewat"
android:textColor="@color/textwhite" />
AndroidManifest文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.soerja.ngalamhistory">
<application
android:allowBackup="true"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SplashAct"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginAct"
android:label="@string/applogin"
android:theme="@style/LogTheme"></activity>
<activity
android:name=".MainActivity"
android:label="@string/home"
android:theme="@style/AppTheme"></activity>
<activity android:name=".RegisAct"
android:label="@string/appdaftar"
android:theme="@style/LogTheme"></activity>
</application>
</manifest>
我非常感谢您的帮助,因为这是我的学校项目:)您正在将文本视图转换为按钮。问题可能是无效的强制转换异常 在XML中,您将“daftar”定义为文本视图,但在java中,您试图将其用作按钮 改变它
Button Reg = (Button) findViewById(R.id.daftar);
对它
或者更改您的XML含义,将“daftar”定义为一个按钮这里您使用的是文本视图id
android:id="@+id/daftar"
作为对声明按钮的引用
Button Reg = (Button) findViewById(R.id.daftar);
所以我认为,这可能是崩溃的原因
尝试以下方法:
在文本xml代码中添加以下内容:
android:onClick="daftar"
为java类添加以下内容:
public void daftar(View v)
{
Intent intent = new Intent(this, RegisAct.class);
startActivity(intent);
}
并删除用于此文本视图的旧java代码:
我希望这能有所帮助。xml中的reg按钮在哪里?您正在尝试将文本视图强制转换为按钮。您的代码不完整,请添加完整的代码它是“daftar”id。我剪切了一些以在此处发布。添加您的logocat崩溃代码谢谢您的努力伙伴:D
android:onClick="daftar"
public void daftar(View v)
{
Intent intent = new Intent(this, RegisAct.class);
startActivity(intent);
}