好的,所以此代碼用於工作,直到我的朋友決定更改Firebase結構,而現在它不工作。即使是現在,如果我更改代碼com.google.firebase.database.DatabaseException:無法將java.lang.String類型的值轉換爲雙倍
這裏的錯誤代碼:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: mapp.com.sg.notymeclient, PID: 26480
com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to double
at com.google.android.gms.internal.zzbqi.zzaB(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzc(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi$zza.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi$zza.zzaG(Unknown Source)
at com.google.android.gms.internal.zzbqi.zze(Unknown Source)
at com.google.android.gms.internal.zzbqi.zzb(Unknown Source)
at com.google.android.gms.internal.zzbqi.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.firebase.ui.database.FirebaseRecyclerAdapter.parseSnapshot(FirebaseRecyclerAdapter.java:151)
at com.firebase.ui.database.FirebaseRecyclerAdapter.getItem(FirebaseRecyclerAdapter.java:140)
at com.firebase.ui.database.FirebaseRecyclerAdapter.onBindViewHolder(FirebaseRecyclerAdapter.java:183)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6062)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6095)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5277)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5153)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2061)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1445)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3374)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3183)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3627)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:846)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:17945)
at android.view.ViewGroup.layout(ViewGroup.java:5812)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
這是我的主要代碼:
mRef = FirebaseDatabase.getInstance().getReference()
.child("users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child("sent");
mRecyclerView = (RecyclerView)view.findViewById(R.id.recycler_view_task);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mAdapter = new TaskAdapter(Task_GSON.class,R.layout.task_list_ui,TaskViewHolder.class,mRef);
mRecyclerView.setAdapter(mAdapter);
mRef.addValueEventListener(new ValueEventListener() {
int index = 0 ;
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot eachTask : dataSnapshot.getChildren()) {
task.add(new Task_GSON());
for(DataSnapshot data : eachTask.getChildren()){
String dataString = data.getValue().toString();
switch (data.getKey()){
case "taskTitle":
task.get(index).setTaskTitle(dataString);
break;
case "taskDescription":
task.get(index).setTaskDescription(dataString);
break;
case "sendBy":
task.get(index).setSendBy(dataString);
break;
case "recieveBy":
task.get(index).setRecieveBy(dataString);
break;
case "locationLong":
task.get(index).setLocationLong(Double.parseDouble(dataString));
break;
case "locationLat":
task.get(index).setLocationLat(Double.parseDouble(dataString));
break;
case "locationName":
task.get(index).setLocationName(dataString);
break;
case "status":
task.get(index).setStatus(Integer.parseInt(dataString));
break;
case "time":
task.get(index).setTime(Long.parseLong(dataString));
break;
}
}
index++;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
,這裏是我的viewholder代碼:
public class TaskViewHolder extends RecyclerView.ViewHolder{
TextView textViewTitle;
TextView textViewDescription;
TextView textViewTime;
TextView textViewTaskAssign;
public TaskViewHolder(View itemView) {
super(itemView);
textViewTitle = (TextView)itemView.findViewById(R.id.text_view_title);
textViewDescription = (TextView)itemView.findViewById(R.id.text_view_task_description);
textViewTime = (TextView)itemView.findViewById(R.id.text_view_time);
textViewTaskAssign = (TextView)itemView.findViewById(R.id.text_view_task_assign);
}
}
這裏是我的適配器代碼:
public class TaskAdapter extends FirebaseRecyclerAdapter<Task_GSON,TaskViewHolder> {
public TaskAdapter(Class<Task_GSON> modelClass, int modelLayout, Class<TaskViewHolder> viewHolderClass, DatabaseReference ref) {
super(modelClass, modelLayout, viewHolderClass, ref);
}
@Override
protected void populateViewHolder(TaskViewHolder viewHolder, Task_GSON model, int position) {
if(model != null){
viewHolder.textViewDescription.setText(model.getTaskDescription());
viewHolder.textViewTitle.setText(model.getTaskTitle());
android.text.format.DateFormat df = new android.text.format.DateFormat();
String reminderDate = df.format("dd/MM/yy hh:mm a" , model.getTime()).toString();
viewHolder.textViewTime.setText(reminderDate);
viewHolder.textViewTaskAssign.setText("send to:" +model.getRecieveBy());
}
}
}
,這裏是我的數據庫結構:
我找不到錯誤和堆棧跟蹤並沒有幫助,因爲它沒有針點的代碼搞亂。
------ UPDATE 1 --------
行,所以我很好奇,如果我的代碼實際上可以查看數據或不和我做了一些測試,我自己 所以首先,我的試圖改變數據庫的結構是這樣的 和它的工作 ,所以我很好奇,我試過其他數據集,但這次改變parrent 成員到用戶像這樣
和它不工作 所以我的假設是,要麼不知何故適配器火力恨字用戶或我的代碼做一些火力適配器恨字用戶作爲原始父級需要用戶
It's難以跟隨你的代碼中,'Query'用'.child( 「發送」)'鍵是不是你的圖片 –
嗨@ Annonymous177,我認爲這是不正確的'mRef = FirebaseDatabase.getInstance()。getReference() .child(「users」) .child(FirebaseAuth。 getInstance()。getCurrentUser()。getUid()) .child(「sent」);'在你的圖像中,最後一個參數是id和'sent'不存在。那是對的? – Jaco
woops錯誤的圖片對不起,我將編輯它 – Annonymous177