java.lang.VerifyError:无法使用Firebase Admin从最终类继承

时间:2018-08-19 12:47:49

标签: java eclipse firebase firebase-authentication

我试图用Eclipse创建一个Java程序来处理我的Firebase实时数据库中的某些问题。我的代码:

package server;

import java.io.FileInputStream;
import java.io.IOException;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
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;



public class Main {

    public static void main(String[] args) throws IOException {
        // Fetch the service account key JSON file contents
        FileInputStream serviceAccount = new FileInputStream("src/server/something.json");

        // Initialize the app with a service account, granting admin privileges
        FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).setDatabaseUrl("https://something.firebaseio.com").build();
        FirebaseApp.initializeApp(options);

        // As an admin, the app has access to read and write all data, regardless of Security Rules
        DatabaseReference ref = FirebaseDatabase.getInstance().getReference("Status");
        ref.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
            int status = dataSnapshot.getValue(Integer.class);
            System.out.println(status);
          }

          @Override
          public void onCancelled(DatabaseError error) { }
        });

    }

}

我的错误:

Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(Unknown Source)
    at java.base/java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at com.google.api.client.googleapis.util.Utils.getDefaultTransport(Utils.java:51)
    at com.google.firebase.FirebaseOptions$Builder.<init>(FirebaseOptions.java:216)
    at server.Main.main(Main.java:24)

我在项目中的导入: firebase-admin-6.3.0.jar; google-api-client-1.24.1.jar; google-api-client-http-1.2.3-alpha.jar; google-api-client-xml-1.2.3-alpha.jar; google-auth-library-oauth2-http-0.10.0.jar; google-http-client-1.24.1.jar。 以及整个图片:https://image.ibb.co/kqNMne/whole.png

1 个答案:

答案 0 :(得分:0)

这似乎是版本不匹配:此处的内容是针对不是final,但现在是{class}的类的版本进行编译的。将您本地具有的依赖项降级为https://mvnrepository.com/artifact/com.google.firebase/firebase-admin/6.3.0表中显示的版本,然后一次更新一个您在此处具有的每个依赖项,直到您知道哪个是导致损坏的因素为止并打开问题在匹配的Github代表中,这样他们就可以正确地解决此问题。