我正在android studio上做一个项目。问题是我无法将片段类添加到我的项目中。开始执行此项目时,我能够添加两个片段类。但是,在完成大约一半的项目之后,现在无法添加第三个片段类。当我添加第三个片段类并运行项目时,将弹出此异常:
java.lang.NoSuchMethodError: No static method zzb(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzaa; or its super classes (declaration of 'com.google.android.gms.common.internal.zzaa' appears in /data/data/com.hashcoder.eegoomain/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-10.0.1_d1c25087bea669c827e484b09b1949315ba5fc5f-classes.dex)
at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5172)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4767)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.access$1600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
我尝试了
android.app.Fragment
或android.support.v4.app.Fragment
。两者都不起作用..... 最佳答案
试试这个,制作一个Java类并从Fragment扩展它。
这是片段类的基本结构。
public class MyFragment extends Fragment{
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.<your xml layout>, container, false);
//Do your work here
return view;
}
}
并确保您从android.support.v4.app.Fragment对其进行了扩展