我試圖從我的firebase數據庫檢索數據並將其顯示在ListView中的TextView中。但是,我在這一行上收到'缺少構造函數'異常:Clients clients = clientsSnapshot.getValue(Clients.class);
。DatabaseException:類缺少一個沒有參數的構造函數
不知道如何解決它。我在Firebase或Android開發方面都不是很有經驗,所以任何幫助都將不勝感激。 乾杯傢伙!
public class ViewProfile extends AppCompatActivity{
ListView listviewClients;
List<Clients> clientsList;
DatabaseReference databaseClients;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_profile);
listviewClients = (ListView) findViewById(R.id.listviewClients);
databaseClients = FirebaseDatabase.getInstance().getReference("clients");
clientsList = new ArrayList<>();
}
@Override
protected void onStart() {
super.onStart();
databaseClients.addValueEventListener (new ValueEventListener() {
@Override
public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
clientsList.clear();
for (com.google.firebase.database.DataSnapshot clientsSnapshot : dataSnapshot.getChildren()) {
Clients clients = clientsSnapshot.getValue(Clients.class);
clientsList.add(clients);
}
ClientsList adapter = new ClientsList(ViewProfile.this, clientsList);
listviewClients.setAdapter(adapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
Clients.java:
public class Clients {
String clientName;
String clientCareer;
Boolean techCB;
Boolean mediCB;
Boolean renewableEnergyNF;
Boolean googleNF;
Boolean novartisNF;
Boolean teslaNF;
Boolean fbLRS;
Boolean applLRS;
Boolean yhooLRS;
Boolean eurusdCB;
Boolean usdrubCU;
Boolean silverCO;
Boolean goldCO;
Boolean gbpusdCU;
Boolean nsdqI;
Boolean sp500I;
// public Clients(String id, String name, String career, Boolean techCB, Boolean mediCB, Boolean renewableEnergyNF, Boolean googleNF, Boolean novartisNF, Boolean teslaNF, Boolean fbLRS, Boolean applLRS, Boolean yhooLRS, Boolean eurusdCB, Boolean usdrubCU, Boolean silverCO, Boolean goldCO, Boolean gbpusdCU, Boolean nsdqI, Boolean sp500I) {
//
// }
public Clients(String id, String clientCareer, String clientName, Boolean techCB, Boolean mediCB, Boolean renewableEnergyNF,
Boolean googleNF, Boolean novartisNF, Boolean teslaNF, Boolean fbLRS, Boolean applLRS, Boolean yhooLRS, Boolean eurusdCB,
Boolean usdrubCU, Boolean silverCO, Boolean goldCO, Boolean gbpusdCU, Boolean nsdqI, Boolean sp500I) {
this.clientName = clientName;
this.clientCareer = clientCareer;
this.techCB = techCB;
this.mediCB = mediCB;
this.renewableEnergyNF = renewableEnergyNF;
this.googleNF = googleNF;
this.novartisNF = novartisNF;
this.teslaNF = teslaNF;
this.fbLRS = fbLRS;
this.applLRS = applLRS;
this.yhooLRS = yhooLRS;
this.eurusdCB = eurusdCB;
this.usdrubCU = usdrubCU;
this.silverCO = silverCO;
this.goldCO = goldCO;
this.gbpusdCU = gbpusdCU;
this.nsdqI = nsdqI;
this.sp500I = sp500I;
}
public String getClientName() {
return clientName;
}
public String getClientCareer() {
return clientCareer;
}
public Boolean getTechCB() {
return techCB;
}
public Boolean getMediCB() {
return mediCB;
}
public Boolean getRenewableEnergyNF() {
return renewableEnergyNF;
}
public Boolean getGoogleNF() {
return googleNF;
}
public Boolean getNovartisNF() {
return novartisNF;
}
public Boolean getTeslaNF() {
return teslaNF;
}
public Boolean getFbLRS() {
return fbLRS;
}
public Boolean getApplLRS() {
return applLRS;
}
public Boolean getYhooLRS() {
return yhooLRS;
}
public Boolean getEurusdCB() {
return eurusdCB;
}
public Boolean getUsdrubCU() {
return usdrubCU;
}
public Boolean getSilverCO() {
return silverCO;
}
public Boolean getGoldCO() {
return goldCO;
}
public Boolean getGbpusdCU() {
return gbpusdCU;
}
public Boolean getNsdqI() {
return nsdqI;
}
public Boolean getSp500I() {
return sp500I;
}
'客戶端類「沒有無參數構造函數 – EpicPandaForce
您需要哪些幫助?你知道什麼是構造函數嗎?你知道什麼是論據嗎?一旦你理解了術語,你應該能夠弄清楚如何解決這個錯誤。 –
發佈「客戶」類代碼.. – rafsanahmad007