连接到Firebase时,Android应用程序崩溃 [英] Android App is crashing when connecting to Firebase

查看:178
本文介绍了连接到Firebase时,Android应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到我的firebase应用程序,但应用程序崩溃时,我正在初始化Firebase与我的应用程序url。

以下行是给出错误 -

Firebase myFirebaseRef = new Firebase(https://firebase-dummy.firebaseio.com/);

给出 IllegalAccessError



截图显示错误

  package com.example.devansh.learnfirebase; 

导入android.os.Bundle;
导入android.support.design.widget.FloatingActionButton;
导入android.support.design.widget.Snackbar;
导入android.support.v7.app.AppCompatActivity;
导入android.support.v7.widget.Toolbar;
导入android.view.View;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.widget.Button;
导入android.widget.TextView;

导入com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.firebase.client.utilities.DefaultRunLoop;

import org.w3c.dom.Text;

公共类MainActivity扩展AppCompatActivity {
Firebase myFirebaseRef;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
myFirebaseRef =新的Firebase(https://firebase-dummy.firebaseio.com/); //此行导致错误
工具栏工具栏=(工具栏)findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab =(FloatingActionButton)findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Snackbar.make(view,Replace with your own action ,Snackbar.LENGTH_LONG)
.setAction(Action,null).show();
myFirebaseRef.child(message)。setValue(你有数据吗? );
}
});

Button recieve =(Button)findViewById(R.id.button);
final TextView dataStatus =(TextView)findViewById(R.id.textview);
recieve.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
myFirebaseRef.child(message)。addValueEventListener(new ValueEventListener (){

@Override
public void onDataChange(DataSnapshot snapshot){
dataStatus.setText(Data received-+ snapshot.getValue()); //输出


@Override public void onCancelled(FirebaseError error){
dataStatus.setText(Data can not be received) ;
}
});
}
});

$ / code>

Gradle文件 -

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.2

defaultConfig {
applicationIdcom.example.devansh.learnfirebase
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}


包装选项{
不包括'META-INF / LICENSE'
不包括'META-INF / LICENSE-FIREBASE.txt'
不包括'META-INF / NOTICE'
}
}

依赖项{
编译fileTree(dir:'libs',include:['* .jar'])
testCompile'junit:junit:4.12'
编译'com.android.support:appcompat-v7:23.1.1'
编译'com.android.support:design:23.1.1'
编译'com.firebase:firebase-client-android: 2.5.1+'
}

这里是我的logcat全文 -

  02-21 00:17:37.779 27073-27073 /? E / Trace:打开跟踪文件时出错:没有这样的文件或目录(2)
02-21 00:17:37.829 27073-27073 /? W / dalvikvm:VFY:无法找到签名中引用的类(Landroid / view / SearchEvent;)
02-21 00:17:37.829 27073-27073 /? W / dalvikvm:VFY:无法解析接口方法17988:Landroid / view / Window $回调; .onSearchRequested(Landroid / view / SearchEvent;)Z
02-21 00:17:37.829 27073-27073 /? W / dalvikvm:VFY:无法解析接口方法17992:Landroid / view / Window $回调; .onWindowStartingActionMode(Landroid / view / ActionMode $回调; I)Landroid / view / ActionMode;
02-21 00:17:37.889 27073-27073 /? W / dalvikvm:VFY:无法解析虚拟方法17884:Landroid / view / ViewGroup; .onRtlPropertiesChanged(I)V
02-21 00:17:37.889 27073-27073 /? W / dalvikvm:VFY:无法解析虚拟方法432:Landroid / content / res / TypedArray; .getChangingConfigurations()I
02-21 00:17:37.889 27073-27073 /? W / dalvikvm:VFY:无法解析虚拟方法454:Landroid / content / res / TypedArray; .getType(I)I
02-21 00:17:37.899 27073-27073 / com.example.devansh.learnfirebase W / dalvikvm:VFY:无法解析直接方法18504:Landroid / widget / LinearLayout $ LayoutParams;。< init> (Landroid / widget / LinearLayout $ LayoutParams;)V
02-21 00:17:37.899 27073-27073 / com.example.devansh.learnfirebase W / dalvikvm:VFY:无法解析直接方法18504:Landroid / Widget /LinearLayout$LayoutParams;.<init> (Landroid / widget / LinearLayout $ LayoutParams;)V
02-21 00:17:37.929 27073-27073 / com.example.devansh.learnfirebase W / dalvikvm:VFY:无法解析虚拟方法30154:Ljava / util /concurrent/ScheduledThreadPoolExecutor;.setRemoveOnCancelPolicy(Z)V
02-21 00:17:37.929 27073-27073 / com.example.devansh.learnfirebase W / dalvikvm:threadid = 1:线程以非捕获的异常退出(group = 0x40e2a468)
02-21 00:17:37.929 27073-27073 / com.example.devansh.learnfirebase E / AndroidRuntime:FATAL EXCEPTION:main
java.lang.IllegalAccessError:试图访问java.util方法.concurrent.ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy :()在com.firebase.client.utilities.DefaultRunLoop上的类com.firebase.client.utilities.DefaultRunLoop上的V.< init>(DefaultRunLoop.java:45)
在com.firebase.client.android.AndroidPlatform.newRunLoop(AndroidPlatform.java:44)
(< init>(AndroidPlatform.java:44)
) at com.firebase.client.core.Context.ensureRunLoop(Context.java:224)
at com.firebase.client.core.Context.initServices(Context.java:111)
at com.firebase .client.core.Context.freeze(Context.java:92)
在com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:55)
在com.firebase.client.Firebase上的com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19)
。< init>(Firebase.java:172)
at com。 firebase.client.Firebase。< init>(Firebase.java:177)
at com.firebase.client.Firebase。< init>(Firebase.java:155)
at com.example。 devansh.learnfirebase.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5066)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java :2391)
at android.app.ActivityThread.access $ 600(ActivityThread.java:151)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1353)
at android .os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper .loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5559)
at java.lang.reflect.Method.invokeNative(Native Method)
在java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1074)
at com.android .internal.os.ZygoteInit.main(ZygoteInit.java:841)
at dalvik.system.NativeStart.main(Native Method)


解决方案Android版Firebase SDK 2.5.1意外引入了对Android API级别21的依赖。



我们正在进行修复。同时,您可以通过使用Firebase SDK 2.5.0或使用API​​级别为21或更高的Android设备/仿真程序来避免此问题。



更新:Android版本2.5.2的Firebase SDK修复了此问题

I am trying to connect to my firebase app but application is crashing when i am initializing Firebase with my app url.
The following line is giving error -
Firebase myFirebaseRef = new Firebase("https://firebase-dummy.firebaseio.com/");
It is giving IllegalAccessError.

Screenshot displaying error

package com.example.devansh.learnfirebase;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;

import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.firebase.client.utilities.DefaultRunLoop;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {
    Firebase myFirebaseRef;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Firebase.setAndroidContext(this);
        myFirebaseRef = new Firebase("https://firebase-dummy.firebaseio.com/"); //This line is causing error
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
                myFirebaseRef.child("message").setValue("Do you have data? You'll love Firebase.");
            }
        });

        Button recieve = (Button) findViewById(R.id.button);
        final TextView dataStatus = (TextView) findViewById(R.id.textview);
        recieve.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                myFirebaseRef.child("message").addValueEventListener(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot snapshot) {
                        dataStatus.setText("Data recieved - "+snapshot.getValue());//prints "Do you have data? You'll love Firebase."
                    }

                    @Override public void onCancelled(FirebaseError error) {
                        dataStatus.setText("Data cannot be received");
                    }
                });
            }
        });
    }

Gradle file -

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.devansh.learnfirebase"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.firebase:firebase-client-android:2.5.1+'
}

Here is full text in my logcat -

02-21 00:17:37.779 27073-27073/? E/Trace: error opening trace file: No such file or directory (2)
02-21 00:17:37.829 27073-27073/? W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
02-21 00:17:37.829 27073-27073/? W/dalvikvm: VFY: unable to resolve interface method 17988: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
02-21 00:17:37.829 27073-27073/? W/dalvikvm: VFY: unable to resolve interface method 17992: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
02-21 00:17:37.889 27073-27073/? W/dalvikvm: VFY: unable to resolve virtual method 17884: Landroid/view/ViewGroup;.onRtlPropertiesChanged (I)V
02-21 00:17:37.889 27073-27073/? W/dalvikvm: VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
02-21 00:17:37.889 27073-27073/? W/dalvikvm: VFY: unable to resolve virtual method 454: Landroid/content/res/TypedArray;.getType (I)I
02-21 00:17:37.899 27073-27073/com.example.devansh.learnfirebase W/dalvikvm: VFY: unable to resolve direct method 18504: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
02-21 00:17:37.899 27073-27073/com.example.devansh.learnfirebase W/dalvikvm: VFY: unable to resolve direct method 18504: Landroid/widget/LinearLayout$LayoutParams;.<init> (Landroid/widget/LinearLayout$LayoutParams;)V
02-21 00:17:37.929 27073-27073/com.example.devansh.learnfirebase W/dalvikvm: VFY: unable to resolve virtual method 30154: Ljava/util/concurrent/ScheduledThreadPoolExecutor;.setRemoveOnCancelPolicy (Z)V
02-21 00:17:37.929 27073-27073/com.example.devansh.learnfirebase W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40e2a468)
02-21 00:17:37.929 27073-27073/com.example.devansh.learnfirebase E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   java.lang.IllegalAccessError: tried to access method java.util.concurrent.ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy:()V from class com.firebase.client.utilities.DefaultRunLoop
                                                                                       at com.firebase.client.utilities.DefaultRunLoop.<init>(DefaultRunLoop.java:45)
                                                                                       at com.firebase.client.android.AndroidPlatform$1.<init>(AndroidPlatform.java:44)
                                                                                       at com.firebase.client.android.AndroidPlatform.newRunLoop(AndroidPlatform.java:44)
                                                                                       at com.firebase.client.core.Context.ensureRunLoop(Context.java:224)
                                                                                       at com.firebase.client.core.Context.initServices(Context.java:111)
                                                                                       at com.firebase.client.core.Context.freeze(Context.java:92)
                                                                                       at com.firebase.client.core.RepoManager.getLocalRepo(RepoManager.java:55)
                                                                                       at com.firebase.client.core.RepoManager.getRepo(RepoManager.java:19)
                                                                                       at com.firebase.client.Firebase.<init>(Firebase.java:172)
                                                                                       at com.firebase.client.Firebase.<init>(Firebase.java:177)
                                                                                       at com.firebase.client.Firebase.<init>(Firebase.java:155)
                                                                                       at com.example.devansh.learnfirebase.MainActivity.onCreate(MainActivity.java:30)
                                                                                       at android.app.Activity.performCreate(Activity.java:5066)
                                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1102)
                                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
                                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
                                                                                       at android.app.ActivityThread.access$600(ActivityThread.java:151)
                                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                       at android.os.Looper.loop(Looper.java:155)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5559)
                                                                                       at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
                                                                                       at dalvik.system.NativeStart.main(Native Method)

解决方案

Version 2.5.1 of the Firebase SDK for Android accidentally introduced a dependency on Android API level 21.

We're working on a fix. In the meantime, you can avoid the problem by using Firebase SDK 2.5.0 or by using an Android device/emulator with API level 21 or higher.

Update: Firebase SDK for Android version 2.5.2 fixes this problem

这篇关于连接到Firebase时,Android应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆