使用FirebaseRecyclerView时出错,在Lcom / google / android / gms / internal / zzaac类中没有静态方法zza(Landroid / app / Application;)V;

时间:2017-06-02 06:56:41

标签: android firebase android-studio-2.3

我正在使用Firebase for Android制作博客应用。 但是我在应用程序启动时遇到错误。我的代码完全正确,但我仍然收到此错误。

这是catlog错误

 java.lang.NoSuchMethodError: No static method zza(Landroid/app/Application;)V in class Lcom/google/android/gms/internal/zzaac; or its super classes (declaration of 'com.google.android.gms.internal.zzaac' appears in /data/app/com.a000webhostapp.androidgrid.devtips-1/split_lib_dependencies_apk.apk)
                                                                                      at com.google.firebase.FirebaseApp.zzcl(Unknown Source)
                                                                                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                                                                                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                                                                                      at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                                                                                      at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
                                                                                      at android.content.ContentProvider.attachInfo(ContentProvider.java:1751)
                                                                                      at android.content.ContentProvider.attachInfo(ContentProvider.java:1726)
                                                                                      at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
                                                                                      at android.app.ActivityThread.installProvider(ActivityThread.java:5853)
                                                                                      at android.app.ActivityThread.installContentProviders(ActivityThread.java:5445)
                                                                                      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5384)
                                                                                      at android.app.ActivityThread.-wrap2(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

这是我的模特Blog.java

public class Blog {

private String title;
private String desc;


public Blog(){

}

public Blog(String title, String desc) {
    this.title = title;
    this.desc = desc;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getDesc() {
    return desc;
}

public void setDesc(String desc) {
    this.desc = desc;
}

}

这是我的MainActivity.java

public class MainActivity extends AppCompatActivity {
private RecyclerView recycleView;
private DatabaseReference fDatabase;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    fDatabase = FirebaseDatabase.getInstance().getReference().child("Blog");

    recycleView = (RecyclerView) findViewById(R.id.recyleView);
    recycleView.setHasFixedSize(true);
    recycleView.setLayoutManager(new LinearLayoutManager(this));
}

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

    FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
            Blog.class,
            R.layout.post_list_layout,
            BlogViewHolder.class,
            fDatabase
    ) {
        @Override
        protected void populateViewHolder(BlogViewHolder viewHolder, Blog model, int position) {

            viewHolder.setTitle(model.getTitle());
            viewHolder.setDesc(model.getDesc());

        }
    };

    recycleView.setAdapter(firebaseRecyclerAdapter);
}

public static class BlogViewHolder extends RecyclerView.ViewHolder {

    View mView;
    public BlogViewHolder(View itemView){
        super(itemView);

        mView = itemView;
    }

    public void setTitle(String title){
        TextView post_title = (TextView) mView.findViewById(R.id.txtBlogTitle);

        post_title.setText(title);

    }

    public void setDesc(String desc){
        TextView post_desc = (TextView) mView.findViewById(R.id.txtBlogDesc);

        post_desc.setText(desc);
    }

}

}

提前致谢...

1 个答案:

答案 0 :(得分:1)

请在firebase文件下的Google-play-services中将所有dependenciesapp.gradle库版本更改为相同版本。