gpt4 book ai didi

java - 因此,我正在使用此应用程序,它没有显示任何错误并已成功安装,但运行后便崩溃了

转载 作者:行者123 更新时间:2023-12-02 07:29:28 24 4
gpt4 key购买 nike

这是我正在处理的代码,我应该再次提及它在Log cat中没有显示任何错误,并显示安装成功,但启动后便崩溃了。我还提供了ManifestGradle和布局代码,以防它们可能出现一些错误。
Activity 类别

package com.example.gazzuptoken;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.example.gazzuptoken.Model.customerInfoModel;
import com.firebase.ui.auth.AuthMethodPickerLayout;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.IdpResponse;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Action;

public class splash_screen_activity extends AppCompatActivity {

private final static int LOGIN_REQUEST_CODE = 19;
private List<AuthUI.IdpConfig> providers;
private FirebaseAuth firebaseAuth;
private FirebaseAuth.AuthStateListener listener;

@BindView(R.id.progress_bar)
ProgressBar progress_bar;

FirebaseDatabase database;
DatabaseReference customerInfoRef;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

init();
}

private void init() {

ButterKnife.bind(this);

database = FirebaseDatabase.getInstance();
customerInfoRef = database.getReference(Common.CUSTOMER_INFO_REFERENCE);

providers = Arrays.asList(
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build());

firebaseAuth = FirebaseAuth.getInstance();
listener = myFirebaseAuth -> {
FirebaseUser user = myFirebaseAuth.getCurrentUser();

if (user != null)
{
checkUserFromFirebase();
}
else showLoginLayout();
};
}

private void checkUserFromFirebase()
{
customerInfoRef.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if (snapshot.exists())
{
Toast.makeText(splash_screen_activity.this, "User Already Registered", Toast.LENGTH_SHORT).show();
}else
{
showRegisterLayout();
}
}

@Override
public void onCancelled(@NonNull DatabaseError error) {
Toast.makeText(splash_screen_activity.this, ""+error.getMessage(), Toast.LENGTH_SHORT).show();
}
});

}

private void showRegisterLayout() {

AlertDialog.Builder builder = new AlertDialog.Builder(this,R.style.DialogTheme);

View itemView = LayoutInflater.from(this).inflate(R.layout.layout_register,null);

TextInputEditText edt_first_name = (TextInputEditText) itemView.findViewById(R.id.edit_first_name);
TextInputEditText edt_last_name = (TextInputEditText) itemView.findViewById(R.id.edit_last_name);
TextInputEditText edt_phone_number = (TextInputEditText) itemView.findViewById(R.id.edit_phone_number);

Button btn_continue = (Button)itemView.findViewById(R.id.btn_register);

//set Data
if (FirebaseAuth.getInstance().getCurrentUser().getPhoneNumber() != null && !TextUtils.isEmpty(FirebaseAuth.getInstance().getCurrentUser().getPhoneNumber()))
edt_phone_number.setText(FirebaseAuth.getInstance().getCurrentUser().getPhoneNumber());

//setView

builder.setView(itemView);
AlertDialog dialog = builder.create();
dialog.show();

btn_continue.setOnClickListener(view -> {

if (TextUtils.isEmpty(edt_first_name.getText().toString()))
{
Toast.makeText(this, "Please Enter First Name", Toast.LENGTH_SHORT).show();
return;
}
else if (TextUtils.isEmpty(edt_last_name.getText().toString()))

{
Toast.makeText(this, "Please Enter Last Name", Toast.LENGTH_SHORT).show();
return;
}
else if (TextUtils.isEmpty(edt_phone_number.getText().toString()))

{
Toast.makeText(this, "Please Enter Your Phone Number", Toast.LENGTH_SHORT).show();
return;
}

else
{
customerInfoModel model = new customerInfoModel();
model.setFirstName(edt_first_name.getText().toString());
model.setLastName(edt_last_name.getText().toString());
model.setPhoneNumber(edt_phone_number.getText().toString());
model.setOrdersPlaced(0);

customerInfoRef.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.setValue(model)
.addOnFailureListener(e ->
{
dialog.dismiss();
Toast.makeText(splash_screen_activity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
)
.addOnSuccessListener(aVoid -> {
Toast.makeText(this, "Registred Successfuly!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
});
}


});

}

@Override
public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_splash_screen);

init();
}

private void showLoginLayout() {

AuthMethodPickerLayout authMethodPickerLayout = new AuthMethodPickerLayout

.Builder(R.layout.layout_sign_in)
.setPhoneButtonId(R.id.btn_phone_sign_in)
.setGoogleButtonId(R.id.btn_google_sign_in)
.build();

startActivityForResult(AuthUI.getInstance()
.createSignInIntentBuilder()
.setAuthMethodPickerLayout(authMethodPickerLayout)
.setIsSmartLockEnabled(false)
.setTheme(R.style.LoginTheme)
.setAvailableProviders(providers)
.build(), LOGIN_REQUEST_CODE);
}

private void delaySplashScreen() {

progress_bar.setVisibility(View.VISIBLE);

Completable.timer(3, TimeUnit.SECONDS,
AndroidSchedulers.mainThread())
.subscribe(() ->
firebaseAuth.addAuthStateListener(listener)
);

}

@Override
protected void onStart() {
super.onStart();
delaySplashScreen();
}

@Override
protected void onStop() {
if (firebaseAuth != null && listener != null)
firebaseAuth.removeAuthStateListener(listener);

super.onStop();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == LOGIN_REQUEST_CODE)
{
IdpResponse response = IdpResponse.fromResultIntent(data);
if (resultCode == RESULT_OK)
{

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
}
else
{
Toast.makeText(this, "[Error]: "+response.getError().getMessage(), Toast.LENGTH_SHORT).show();
}
}

}
}
布局代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="20dp"
android:padding="16dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/register_text"
android:textColor="@color/black"
android:fontFamily="@font/segoeui"
android:textSize="18dp"
android:gravity="center"
>

</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/account"
android:textColor="@color/colorPrimary"
android:fontFamily="@font/cocogoose"
android:textSize="26dp"
android:gravity="center"
>
</TextView>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">

<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="4dp"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:hint="@string/first_name" />


</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="4dp"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:hint="@string/last_name" />

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_phone_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:hint="@string/phone_number">


</com.google.android.material.textfield.TextInputEditText>

</com.google.android.material.textfield.TextInputLayout>

</LinearLayout>

</LinearLayout>

<Button
android:layout_alignParentBottom="true"
android:id="@+id/btn_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.Button"
android:text="@string/continue_text"
android:textColor="@color/white"
android:layout_margin="50dp"

/>
</RelativeLayout>
清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gazzuptoken">

<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/Theme.AppCompat.Light.NoActionBar">
<activity android:name=".splash_screen_activity"
android:theme="@style/SplashTheme"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Gradle构建脚本
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 30
buildToolsVersion "30.0.1"

defaultConfig {
applicationId "com.example.gazzuptoken"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.2'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//Rx Java

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'

//FireBase UI

implementation 'com.firebaseui:firebase-ui-auth:6.2.1'

//Material

implementation 'com.google.android.material:material:1.1.0'

//ButterKnife
implementation 'com.jakewharton:butterknife:10.2.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'

//Firebase Database

implementation 'com.google.firebase:firebase-database:19.3.1'

}

最佳答案

我至少看到一个错误。您没有为 Activity 设置布局资源:

        @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView is missing here
init();
}
将其他 setContentView(R.layout.activity_splash_screen);方法中的 onCreate行粘贴到上述方法中。

关于java - 因此,我正在使用此应用程序,它没有显示任何错误并已成功安装,但运行后便崩溃了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62995994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com