我无法解决此错误,有人可以帮我吗?我正在使用Firebase,但是此错误即将出现
com.google.firebase.database.DatabaseException:无法转换对象 类型为java.lang.String的类型**
public class riderdashboard extends AppCompatActivity {
Button btn;
Button btn2;
ListView historylistView;
private DatabaseReference mRef;
private DatabaseReference mdsRef;
// private DatabaseReference databaseRevenue;
List<Jobhstory> jobhstoryList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_riderdashboard);
mRef=FirebaseDatabase.getInstance().getReference();
mdsRef=mRef.child("Data");
Log.i("dta", mdsRef.toString());
btn = (Button) findViewById(R.id.revenue);
btn2 = (Button) findViewById(R.id.jobhistory);
historylistView = (ListView) findViewById(R.id.historylistview);
jobhstoryList = new ArrayList<>();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mdsRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
// jobhstoryList.clear();
for (DataSnapshot revenuesnapshot : dataSnapshot.getChildren()) {
Jobhstory jobhstory = revenuesnapshot.getValue(Jobhstory.class);
// String time=revenuesnapshot.child("Data").getValue(String.class);
Log.i("jobhstory", jobhstory.toString());
// Log.i("tetxe",time);
jobhstoryList.add(jobhstory);
}
Jobhistory adapter = new Jobhistory(riderdashboard.this, jobhstoryList);
historylistView.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
});
}
}
Jobhstory.java此类用于构造函数和getter()
public class Jobhstory {
String dta;
String tm;
String earn;
public Jobhstory(String date, String time, String earn) {
this.dta = date;
this.tm = time;
this.earn = earn;
}
public String getDta() {
return dta;
}
public String getTm() {
return tm;
}
public String getEarn() {
return earn;
}
}
Jobhistory.java 该类用作arrayAdapter
public class Jobhistory extends ArrayAdapter<Jobhstory>{
private Activity context;
private List<Jobhstory> revenue;
public Jobhistory( Activity context1, List<Jobhstory> revenue) {
super(context1,R.layout.historylayout,revenue);
this.context = context1;
this.revenue = revenue;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View view=inflater.inflate(R.layout.historylayout,null,true);
TextView textView1=(TextView)view.findViewById(R.id.date);
TextView textView2=(TextView)view.findViewById(R.id.time);
TextView textView3=(TextView)view.findViewById(R.id.earn);
Jobhstory jobhstory=revenue.get(position);
textView1.setText(jobhstory.getDta());
textView2.setText(jobhstory.getTm());
textView3.setText(jobhstory.getEarn());
return view;
}
}