在我第一次为该Utils类运行代码时,我仍然遇到java.lang.NoClassDefFoundError
public class FBase {
public static String myUID = FirebaseAuth.getInstance().getCurrentUser().getUid();
public static DatabaseReference dbUsersRef = FirebaseDatabase.getInstance().getReference("Users");
public static DatabaseReference dbMessagesRef = FirebaseDatabase.getInstance().getReference("Messages");
public static DatabaseReference dbNotificationsRef = FirebaseDatabase.getInstance().getReference("Notifications");
public static DatabaseReference dbBlockRef = FirebaseDatabase.getInstance().getReference("Block");
public static DatabaseReference dbUnReadMessagesRef = FirebaseDatabase.getInstance().getReference("posts");
public static DatabaseReference dbLastMessagesRef = FirebaseDatabase.getInstance().getReference("LastMessages");
public static StorageReference dbStorageReference = FirebaseStorage.getInstance().getReference().child("Photos");
}
这是我上一堂课的代码
FBase.dbUsersRef.orderByKey().equalTo(FBase.myUID).addListenerForSingleValueEvent(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
User model = data.getValue(User.class);
name =model.getName();
city =model.getCity();
state = model.getState();
country = model.getCountry();
}
@Override
public void onCancelled(DatabaseError databaseError) { }
});
}
我已经阅读了documentation来解决此错误,该错误建议添加
android {
defaultConfig {
...
multiDexEnabled true
}
...
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
并在扩展Application的类上覆盖此方法
class MyApp : Application() , LifecycleObserver {
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(this)
}
}
我还编辑了gradle.properties文件并更改了这一行
org.gradle.jvmargs=-Xmx1536m
到
org.gradle.jvmargs=-Xmx2048m -XX\:MaxHeapSize\=1024m
对不起,我在首次运行时从firebase解析数据时仍然出现此错误
我现在该怎么办?