登录页面不会打开配置文件活动

我是java编码和Android Studio的新手,所以请耐心等待,并感谢您提供的任何帮助。用户在注册活动页面中注册之后,我希望他们能够按登录页面中的登录按钮,然后让应用程序进入配置文件活动页面。但是,输入用户名和密码并按登录页面中的登录按钮后,应用程序崩溃。这里是一组代码,这第一组是“LoginPageActivity.java”活动中的登录页面代码。登录页面不会打开配置文件活动

package com.example.xxxx.safetyxxxxxxx; 

import android.content.Intent;

import android.support.annotation.NonNull;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.util.Patterns;

import android.view.View;

import android.widget.EditText;

import android.widget.ProgressBar;

import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;

import com.google.android.gms.tasks.Task;

import com.google.firebase.auth.AuthResult;

import com.google.firebase.auth.FirebaseAuth;

public class LoginPageActivity extends AppCompatActivity implements View.OnClickListener{

FirebaseAuth mAuth;

EditText editTextEmail, editTextPassword;

ProgressBar progressBar;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login_page);

mAuth = FirebaseAuth.getInstance();

editTextEmail = findViewById(R.id.editTextEmail);

editTextPassword= (EditText) findViewById(R.id.editTextPassword);

progressBar = (ProgressBar) findViewById(R.id.progressbar);

findViewById(R.id.textViewSignUp).setOnClickListener(this);

findViewById(R.id.buttonLogin).setOnClickListener(this);

}

private void userLogin(){

String email = editTextEmail.getText().toString().trim();

String password = editTextPassword.getText().toString().trim();

if(email.isEmpty()){

editTextEmail.setError("Email is required");

editTextEmail.requestFocus();

return;

}

if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()){

editTextEmail.setError("Please enter a valid email");

editTextEmail.requestFocus();

return;

}

if(password.isEmpty()){

editTextPassword.setError("Password is required");

editTextPassword.requestFocus();

return;

}

if(password.length()<6){

editTextPassword.setError("Minimum length of password should be 6");

editTextPassword.requestFocus();

return;

}

progressBar.setVisibility(View.VISIBLE);

mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {

@Override

public void onComplete(@NonNull Task<AuthResult> task) {

progressBar.setVisibility(View.GONE);

if (task.isSuccessful()) {

Intent intent = new Intent(LoginPageActivity.this, ProfileActivity.class);

startActivity(intent);

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

finish();

} else {

Toast.makeText(getApplicationContext(), task.getException().getMessage(), Toast.LENGTH_SHORT).show();

}

}

});

}

@Override

public void onClick(View view) {

switch (view.getId()) {

case R.id.textViewSignUp:

startActivity(new Intent(this, SignUpActivity.class));

break;

case R.id.buttonLogin:

userLogin();

break;

}

}

}

这里被称为 “ProfileActivity.java” 的姿态的活动

package com.example.xxxx.safetyxxxxxxx; 

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class ProfileActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_profile);

}

}

下面是Android清单代码。我已经尝试了许多不同的变体,基于过去的研究和以前的问题,使用相同的logcat错误来声明此清单中的ProfileActivity类。

<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.xxxx.safetyxxxxxxx">

<application

android:name=".Database"

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>

<activity android:name=".LoginPageActivity"

android:label="@string/app_name"/>

<activity android:name=".Main2Activity" />

<activity

android:name=".SignUpActivity"

android:label="@string/app_name">

</activity>

<activity android:name=".ProfileActivity"

android:label="@string/app_name"/>

</application>

</manifest>

这里是logcat的错误

12月12日至2日:04:56.008 2644年至2644年/ com.example.xxxx.safetyxxxxxxx E/AndroidRuntime:致命异常:主

Process: com.example.xxxx.safetyxxxxxxx, PID: 2644 

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.xxxx.safetyxxxxxxx/com.example.xxxx.safetyxxxxxxx.ProfileActivity}; have you declared this activity in your AndroidManifest.xml?

at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1933)

at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)

at android.app.Activity.startActivityForResult(Activity.java:4488)

at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)

at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)

at android.app.Activity.startActivityForResult(Activity.java:4446)

at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)

at android.app.Activity.startActivity(Activity.java:4807)

at android.app.Activity.startActivity(Activity.java:4775)

at com.example.xxxx.safetyxxxxxxx.LoginPageActivity$1.onComplete(LoginPageActivity.java:79)

at com.google.android.gms.tasks.zzf.run(Unknown Source:23)

at android.os.Handler.handleCallback(Handler.java:790)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:164)

at android.app.ActivityThread.main(ActivityThread.java:6494)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

最后在需要的情况下,这里是被称为“activity_login_page.xml”的登录页面布局代码

<?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=".LoginPageActivity">

<TextView

android:id="@+id/textView2"

android:layout_width="0dp"

android:layout_height="53dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:text="Hi, Welcome to Safety xxxxxxx Please Login or Signup"

android:textAlignment="center"

android:textColor="@android:color/holo_green_dark"

android:textSize="20sp"

app:layout_constraintBottom_toTopOf="@+id/buttonLogin"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.66"></TextView>

<Button

android:id="@+id/buttonLogin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:text="Login"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.87" />

<EditText

android:id="@+id/editTextEmail"

android:layout_width="346dp"

android:layout_height="50dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:ems="10"

android:hint="email"

android:inputType="textEmailAddress"

app:layout_constraintBottom_toTopOf="@+id/editTextPassword"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="@+id/textView2"

app:layout_constraintVertical_bias="0.95" />

<EditText

android:id="@+id/editTextPassword"

android:layout_width="346dp"

android:layout_height="50dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:ems="10"

android:inputType="textPassword"

android:hint=" Password"

app:layout_constraintBottom_toTopOf="@+id/buttonLogin"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView2"

app:layout_constraintVertical_bias="0.87" />

<ImageView

android:id="@+id/imageView2"

android:layout_width="219dp"

android:layout_height="229dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

app:layout_constraintBottom_toTopOf="@+id/editTextEmail"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.503"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.233"

app:srcCompat="@drawable/safetyxxx" />

<TextView

android:id="@+id/textViewSignUp"

android:layout_width="345dp"

android:layout_height="35dp"

android:layout_marginBottom="8dp"

android:layout_marginEnd="8dp"

android:layout_marginStart="8dp"

android:layout_marginTop="8dp"

android:text="Do Not Have An Account? Click Here"

android:textAlignment="center"

android:textColor="@android:color/holo_green_dark"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/buttonLogin" />

<android.support.v4.widget.ContentLoadingProgressBar

android:id="@+id/progressbar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:visibility="gone"/>

</android.support.constraint.ConstraintLayout>

回答:

经过多次尝试,我需要做的只是按重建项目按钮。它在那之后完美运作。

感谢所有试图提供帮助的人。

回答:

它被清除arly在致命消息中表示:android.content.ActivityNotFoundException:无法找到显式活动类{com.example.xxxx.safetyxxxxxxx/com.example.xxxx.safetyxxxxxxx.ProfileActivity};你有没有在你的AndroidManifest.xml中声明这个活动?

所以,你在清单文件中乱七八糟:请尝试从活动的定义中移除包名:例如像“activity android:name =”com.example.xxxx.safetyxxxxxxx.LoginPageActivity“之类的叮咬应该更改为“activity android:name =”。LoginPageActivity“

此致敬礼!

回答:

您可以试试这个镜头。

<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.xxxx.safetyxxxxxxx">

<application

android:name=".Database"

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>

<activity android:name=".LoginPageActivity"

android:label="@string/app_name">

</activity>

<activity android:name=".Main2Activity">

</activity>

<activity

android:name=".SignUpActivity"

android:label="@string/app_name">

</activity>

<activity android:name=".ProfileActivity"

android:label="@string/app_name">

</activity>

</application>

</manifest>

这可能不会帮助,但我会亲自给我一枪。

以上是 登录页面不会打开配置文件活动 的全部内容, 来源链接: utcz.com/qa/257899.html

回到顶部