在文本视图主屏幕中单击,然后显示“java.lang.NullPointerException”。此错误出现在logcat.xml中,并且无法转到forgotpassword.xml
当我点击文本视图时忘记了你的密码?在主屏幕main.xml中,它无法指向forgotpassword.xml并崩溃。其他活动没有问题 main.xml在文本视图主屏幕中单击,然后显示“java.lang.NullPointerException”。此错误出现在logcat.xml中,并且无法转到forgotpassword.xml,java,android,xml,Java,Android,Xml,当我点击文本视图时忘记了你的密码?在主屏幕main.xml中,它无法指向forgotpassword.xml并崩溃。其他活动没有问题 main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:backg
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/images" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:layout_marginLeft="19dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="2dp"
android:text="Plot Out"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignTop="@+id/textView1"
android:layout_marginTop="1dp"
android:text="Bring Me Out"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="84dp"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="53dp"
android:layout_marginTop="2dp"
android:src="@drawable/logo" />
<Button
android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="1dp"
android:layout_marginLeft="40dp"
android:text="Login"
android:width="100sp" />
<Button
android:id="@+id/btnRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="40dp"
android:text="Register"
android:width="100sp" />
<TextView
android:id="@+id/link_to_forgotpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:layout_centerHorizontal="true"
android:text="Forgot Your Password?"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
forgotpassword.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/images">
<TextView
android:layout_width="190dp"
android:layout_height="40dp"
android:text="Reset your Password"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="17dp"
android:textColor="#000000"/>
<TextView
android:layout_width="180dp"
android:layout_height="40dp"
android:text="Enter your Email Id"
android:id="@+id/textView2"
android:textColor="#000000"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:textSize="17dp"/>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="@+id/forpas"
android:textColor="#000000"
android:layout_below="@+id/textView2"
android:hint="Email"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>
<Button
android:layout_width="150dp"
android:layout_height="40dp"
android:text="Reset"
android:textColor="#000000"
android:id="@+id/respass"
android:layout_below="@+id/forpas"
android:layout_alignParentLeft="true"
android:textSize="13dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="56dp"
android:id="@+id/alert"
android:layout_below="@+id/respass"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:textColor="#000000"/>
<Button
android:layout_width="150dp"
android:layout_height="40dp"
android:text="Back to Login"
android:id="@+id/bktolog"
android:textColor="#000000"
android:layout_below="@+id/btnback_to_login"
android:layout_alignParentRight="true"
android:textSize="13dp"/>
</RelativeLayout>
您需要将“链接到”密码设置为可单击。请参阅文档
这也可以通过android在xml中实现:clickable=true哪一行抛出NPE?如果您的描述是准确的,那么错误可能在ForgotPasswordActivity中。请发布该类和您的日志。先生,我已经发布了ForgotPasswordActivity.java和forgotpassword.xml。您在布局xml中没有ID为btnback_to_登录的按钮,因此您的代码中的主屏幕为空。forgotpassword.xml中有btnback_to_登录
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/images">
<TextView
android:layout_width="190dp"
android:layout_height="40dp"
android:text="Reset your Password"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="17dp"
android:textColor="#000000"/>
<TextView
android:layout_width="180dp"
android:layout_height="40dp"
android:text="Enter your Email Id"
android:id="@+id/textView2"
android:textColor="#000000"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:textSize="17dp"/>
<EditText
android:layout_width="250dp"
android:layout_height="40dp"
android:id="@+id/forpas"
android:textColor="#000000"
android:layout_below="@+id/textView2"
android:hint="Email"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"/>
<Button
android:layout_width="150dp"
android:layout_height="40dp"
android:text="Reset"
android:textColor="#000000"
android:id="@+id/respass"
android:layout_below="@+id/forpas"
android:layout_alignParentLeft="true"
android:textSize="13dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="56dp"
android:id="@+id/alert"
android:layout_below="@+id/respass"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:textColor="#000000"/>
<Button
android:layout_width="150dp"
android:layout_height="40dp"
android:text="Back to Login"
android:id="@+id/bktolog"
android:textColor="#000000"
android:layout_below="@+id/btnback_to_login"
android:layout_alignParentRight="true"
android:textSize="13dp"/>
</RelativeLayout>
package com.plotout.loginandregister;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class ForgotPasswordActivity extends Activity {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Set View to forgotpassword.xml
setContentView(R.layout.forgotpassword);
Button mainScreen = (Button) findViewById(R.id.btnback_to_login);
// Listening to main Screen link
mainScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Switching to Register screen
Intent i = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(i);
}
});
}
}