#java #android #xml #firebase
#java #Android #xml #firebase
Вопрос:
Я создавал приложение с аутентификацией firebase. Сначала все шло хорошо, но позже, когда я открываю приложение, оно немедленно отключается. Я попытался перезапустить Android studio, но ничего не произошло. Я только понимаю, что это что-то о макете, но не могу понять, в чем реальная проблема.
Я не знаю, что вызывает эту ошибку.
`A/art: art/runtime/thread.cc:1336] No pending exception expected: java.lang.NoClassDefFoundError: androidx.core.view.ViewCompat$2
art/runtime/thread.cc:1336] at java.lang.Class dalvik.system.DexFile.defineClassNative(java.lang.String, java.lang.ClassLoader, java.lang.Object) (DexFile.java:-2)
art/runtime/thread.cc:1336] at java.lang.Class dalvik.system.DexFile.defineClass(java.lang.String, java.lang.ClassLoader, java.lang.Object, java.util.List) (DexFile.java:226)
art/runtime/thread.cc:1336] at java.lang.Class dalvik.system.DexFile.loadClassBinaryName(java.lang.String, java.lang.ClassLoader, java.util.List) (DexFile.java:219)
art/runtime/thread.cc:1336] at java.lang.Class dalvik.system.DexPathList.findClass(java.lang.String, java.util.List) (DexPathList.java:338)
art/runtime/thread.cc:1336] at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:54)
art/runtime/thread.cc:1336] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:511)
art/runtime/thread.cc:1336] at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:469)
art/runtime/thread.cc:1336] at void androidx.appcompat.widget.ActionBarContainer.<init>(android.content.Context, android.util.AttributeSet) (ActionBarContainer.java:63)
art/runtime/thread.cc:1336] at java.lang.Object java.lang.reflect.Constructor.newInstance!(java.lang.Object[]) (Constructor.java:-2)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.createView(java.lang.String, java.lang.String, android.util.AttributeSet) (LayoutInflater.java:628)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:809)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.createViewFromTag(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet) (LayoutInflater.java:749)
art/runtime/thread.cc:1336] at void android.view.LayoutInflater.rInflate(org.xmlpull.v1.XmlPullParser, android.view.View, android.content.Context, android.util.AttributeSet, boolean) (LayoutInflater.java:880)
art/runtime/thread.cc:1336] at void android.view.LayoutInflater.rInflateChildren(org.xmlpull.v1.XmlPullParser, android.view.View, android.util.AttributeSet, boolean) (LayoutInflater.java:843)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.inflate(org.xmlpull.v1.XmlPullParser, android.view.ViewGroup, boolean) (LayoutInflater.java:521)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup, boolean) (LayoutInflater.java:429)
art/runtime/thread.cc:1336] at android.view.View android.view.LayoutInflater.inflate(int, android.view.ViewGroup) (LayoutInflater.java:380)
art/runtime/thread.cc:1336] at android.view.ViewGroup androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor() (AppCompatDelegateImpl.java:896)
art/runtime/thread.cc:1336] at void androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor() (AppCompatDelegateImpl.java:806)
art/runtime/thread.cc:1336] at void androidx.appcompat.app.AppCompatDelegateImpl.setContentView(int) (AppCompatDelegateImpl.java:693)
art/runtime/thread.cc:1336] at void androidx.appcompat.app.AppCompatActivity.setContentView(int) (AppCompatActivity.java:170)
art/runtime/thread.cc:1336] at void com.example.uchat.LoginActivity.onCreate(android.os.Bundle) (LoginActivity.java:43)
art/runtime/thread.cc:1336] at void android.app.Activity.performCreate(android.os.Bundle) (Activity.java:6308)
art/runtime/thread.cc:1336] at void android.app.Instrumentation.callActivityOnCreate(android.app.Activity, android.os.Bundle) (Instrumentation.java:1114)
art/runtime/thread.cc:1336] at android.app.Activity android.app.ActivityThread.performLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2445)
art/runtime/thread.cc:1336] at void android.app.ActivityThread.handleLaunchActivity(android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:2552)
art/runtime/thread.cc:1336] at void android.app.ActivityThread.access$1000(android.app.ActivityThread, android.app.ActivityThread$ActivityClientRecord, android.content.Intent) (ActivityThread.java:166)
art/runtime/thread.cc:1336] at void android.app.ActivityThread$H.handleMessage(android.os.Message) (ActivityThread.java:1399)
art/runtime/thread.cc:1336] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
art/runtime/thread.cc:1336] at void android.os.Looper.loop() (Looper.java:148)
art/runtime/thread.cc:1336] at void android.app.ActivityThread.main(java.lang.String[]) (ActivityThread.java:5541)
art/runtime/thread.cc:1336] at java.lang.Object java.lang.reflect.Method.invoke!(java.lang.Object, java.lang.Object[]) (Method.java:-2)
art/runtime/thread.cc:1336] at void com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run() (ZygoteInit.java:853)
art/runtime/thread.cc:1336] at void com.android.internal.os.ZygoteInit.main(java.lang.String[]) (ZygoteInit.java:737)
art/runtime/thread.cc:1336]
A/art: art/runtime/barrier.cc:90] Check failed: count_ == 0 (count_=-1, 0=0) Attempted to destroy barrier with non zero count
art/runtime/runtime.cc:366] Runtime aborting --- recursively, so no thread-specific detail!
art/runtime/runtime.cc:366]
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 31060 (m.example.uchat)`
Это макет:
`<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".LoginActivity">
<ImageView
android:layout_width="154dp"
android:layout_height="171dp"
android:src="@drawable/ic_baseline_account_circle_24"
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.0" />
<EditText
android:id="@ id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="28dp"
android:hint="Enter your phone number"
android:textColorHint="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.696"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.336" />
<EditText
android:id="@ id/code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginRight="28dp"
android:hint="Enter verification code"
android:textColor="#000000"
android:textColorHint="#000000"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.321"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.448" />
<Button
android:id="@ id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:background="@drawable/bg_round"
android:padding="6dp"
android:text="Send Verification code"
android:textColor="#ffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.581" />
</androidx.constraintlayout.widget.ConstraintLayout>`
Это основное действие:
package com.example.uchat;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseException;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;
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.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class LoginActivity extends AppCompatActivity {
private EditText phoneNumber, code;
private Button sendBtn;
private PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallBack;
String verificationId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(this);
userIsLoggedIn();
phoneNumber = findViewById(R.id.phoneNumber);
code = findViewById(R.id.code);
sendBtn = findViewById(R.id.sendBtn);
sendBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(verificationId != null)
verifyPhoneNumberWithCode();
else
startPhoneNumberVerification();
}
});
mCallBack = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
SignInWithPhoneAuthCredential(phoneAuthCredential);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
}
@Override
public void onCodeSent(@NonNull String s, @NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
verificationId = s;
sendBtn.setText("Verify Code");
}
};
}
private void verifyPhoneNumberWithCode(){
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(verificationId, code.getText().toString());
SignInWithPhoneAuthCredential(credential);
}
private void SignInWithPhoneAuthCredential(PhoneAuthCredential phoneAuthCredential) {
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null){
final DatabaseReference userdb = FirebaseDatabase.getInstance().getReference().child("user").child(user.getUid());
userdb.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(!snapshot.exists()){
Map<String, Object> userMap = new HashMap<>();
userMap.put("phone", user.getPhoneNumber());
userMap .put("name", user.getPhoneNumber());
}
userIsLoggedIn();
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
}
else{
System.out.println("unsuccesfull");
}
}
});
}
private void userIsLoggedIn() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null){
startActivity(new Intent(getApplicationContext(), MainPageActivity.class));
finish();
return;
}
}
public void startPhoneNumberVerification(){
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phoneNumber.getText().toString(),
60,
TimeUnit.SECONDS,
this,
mCallBack);
}
}
Комментарии:
1. Опубликуйте свой
build.gradle
файл
Ответ №1:
android:textColor="#ffff"
Цвет текста для вашей кнопки неверен. Шестнадцатеричные цвета должны содержать только 3 или 6 символов или 8, если вы применяете альфа.