gpt4 book ai didi

java - 如何将数组转换为列表而不是 Firebase?

转载 作者:行者123 更新时间:2023-11-30 00:43:32 24 4
gpt4 key购买 nike

我在我的 Android Studio 中收到此错误。以前版本的 Firebase SDK 支持此功能,但新版 SDK 不支持此功能。请帮助解决此问题。

02-11 23:38:47.647  14487-14487/com.potenza_pvt_ltd.AAPS E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.potenza_pvt_ltd.AAPS, PID: 14487
Theme: themes:{default=overlay:com.cyngn.hexo, iconPack:com.cyngn.hexo, fontPkg:com.cyngn.hexo, com.android.systemui=overlay:com.cyngn.hexo, com.android.systemui.navbar=overlay:com.cyngn.hexo}
com.google.firebase.database.DatabaseException: Converting to Arrays is not supported, please use Listsinstead
at com.google.android.gms.internal.zzaix.zzb(Unknown Source)
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.android.gms.internal.zzaix.zzb(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzaix$zza.zzaC(Unknown Source)
at com.google.android.gms.internal.zzaix.zzd(Unknown Source)
at com.google.android.gms.internal.zzaix.zzb(Unknown Source)
at com.google.android.gms.internal.zzaix.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.potenza_pvt_ltd.AAPS.ExitReceipt$7.onChildAdded(ExitReceipt.java:322)
at com.google.android.gms.internal.zzaer.zza(Unknown Source)
at com.google.android.gms.internal.zzagp.zzSu(Unknown Source)
at com.google.android.gms.internal.zzags$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这是我的 POJO 类

@IgnoreExtraProperties
public class TariffDetails {

private String vehicle_type;
private String key;
private String total_slab_hrs;
private String no_of_slab_hrs;
private String inc_dur_hrs;
private String tariff;
private String code;
private int[][] arr;

public TariffDetails() {

/*Blank default constructor essential for Firebase*/
}
public TariffDetails(String a){

}
@JsonProperty("Key")
public String getKey(){
return key;
}
@JsonProperty("Key")
public void setKey(String key){
this.key=key;
}
@JsonProperty("vtype")
public String getVehicle_type(){
return vehicle_type;
}
@JsonProperty("vtype")
public void setVehicle_type(String key){
this.vehicle_type=key;
}
@JsonProperty("total_slab_hrs")
public String getTotal_slab_hrs(){
return total_slab_hrs;
}
@JsonProperty("total_slab_hrs")
public void setTotal_slab_hrs(String key){
this.total_slab_hrs=key;
}
@JsonProperty("no_of_slab_hrs")
public String getNo_of_slab_hrs(){
return no_of_slab_hrs;
}
@JsonProperty("no_of_slab_hrs")
public void setNo_of_slab_hrs(String key){
this.no_of_slab_hrs=key;
}
@JsonProperty("inc_dur_hrs")
public String getInc_dur_hrs(){
return inc_dur_hrs;
}
@JsonProperty("inc_dur_hrs")
public void setInc_dur_hrs(String key){
this.inc_dur_hrs=key;
}
@JsonProperty("inslipp_tariff")
public String getInslip_tariff(){
return tariff;
}
@JsonProperty("inslipp_tariff")
public void setInslip_tariff(String key){
this.tariff=key;
}
@JsonProperty("code")
public String getCode(){
return code;
}
@JsonProperty("code")
public void setCode(String key){
this.code=key;
}
@JsonProperty("arr")
public int[][] getArr(){
return arr;
}
@JsonProperty("arr")
public void setArr(int[][] a){
this.arr=a;
}


}

这是我称之为主要部分的地方。

Query queryRef1 = reference.child("users").child("Tariff_Details").orderByChild("vtype").equalTo(code_value_1);
queryRef1.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Log.d("value of get data", dataSnapshot.getKey());
TariffDetails post = dataSnapshot.getValue(TariffDetails.class);
tar_arr = post.getArr();
for (int i = 0; i < tar_arr.length; i++) {
for (int j = 0; j < 3; j++) {
Log.d("ARR", String.valueOf(tar_arr[i][j]));
arr.add(tar_arr[i][j]);
}
}
if(tar_arr!=null){
adapter = new CustomGrid(getApplicationContext(), tar_arr,code_value_1);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(parent.getContext(), "You Clicked at " + position, Toast.LENGTH_SHORT).show();
}
});
adapter.notifyDataSetChanged();
}
f[0] =1;
pb1.setVisibility(View.GONE);
linear_layout.setVisibility(View.VISIBLE);
}

@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.d("value of get data", dataSnapshot.getKey());
TariffDetails post = dataSnapshot.getValue(TariffDetails.class);
tar_arr = post.getArr();
for (int i = 0; i < tar_arr.length; i++) {
for (int j = 0; j < 3; j++) {
Log.d("ARR", String.valueOf(tar_arr[i][j]));
arr.add(tar_arr[i][j]);
}
}
if(tar_arr!=null){
adapter = new CustomGrid(getApplicationContext(), tar_arr,code_value_1);
gridView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
}

@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
tar_arr = null;
adapter.notifyDataSetChanged();
}

@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {

}

@Override
public void onCancelled(DatabaseError firebaseError) {

}
});

最佳答案

简单地使用 Arrays.asList(yourArray) 将其作为列表。

关于java - 如何将数组转换为列表而不是 Firebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42179440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com