2016-06-15 3 views
2

유형으로 변환 할 수 없습니다. FirebaseDatabase에서 데이터를 검색하는 데 약간 문제가 있습니다.com.google.firebase.database.DatabaseException : java.lang.String 유형의 객체를

나는 올바른 방법으로 모든 일을했지만 여전히이 오류가 발생하고 앱이 다운됩니다.

com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.rana.sahaj.myyu.profile.ExtraProfilClass 

ExtraProfilClass

@IgnoreExtraProperties 
public class ExtraProfilClass { 
private String branch; 
private String campus; 
private String course; 
private String gplusURL; 
private String hashname; 
private String picurl; 
private String picurl50DP; 
private String userEmail; 
private String userNAME; 
private String yearFrom; 
private String yearTo; 
public ExtraProfilClass(){ 
    //Empty constructor for firebase 
} 


public ExtraProfilClass(String branch, String campus, String course, String gplusURL, String hashname, String picurl, String picurl50DP, String userEmail, String userNAME, String yearFrom, String yearTo) { 
    this.branch = branch; 
    this.campus = campus; 
    this.course = course; 
    this.gplusURL = gplusURL; 
    this.hashname = hashname; 
    this.picurl = picurl; 
    this.picurl50DP = picurl50DP; 
    this.userEmail = userEmail; 
    this.userNAME = userNAME; 
    this.yearFrom = yearFrom; 
    this.yearTo = yearTo; 
} 

public String getBranch() { 
    return branch; 
} 

public void setBranch(String branch) { 
    this.branch = branch; 
} 

public String getCampus() { 
    return campus; 
} 

public void setCampus(String campus) { 
    this.campus = campus; 
} 

public String getCourse() { 
    return course; 
} 

public void setCourse(String course) { 
    this.course = course; 
} 

public String getGplusURL() { 
    return gplusURL; 
} 

public void setGplusURL(String gplusURL) { 
    this.gplusURL = gplusURL; 
} 

public String getHashname() { 
    return hashname; 
} 

public void setHashname(String hashname) { 
    this.hashname = hashname; 
} 

public String getPicurl() { 
    return picurl; 
} 

public void setPicurl(String picurl) { 
    this.picurl = picurl; 
} 

public String getPicurl50DP() { 
    return picurl50DP; 
} 

public void setPicurl50DP(String picurl50DP) { 
    this.picurl50DP = picurl50DP; 
} 

public String getUserEmail() { 
    return userEmail; 
} 

public void setUserEmail(String userEmail) { 
    this.userEmail = userEmail; 
} 

public String getUserNAME() { 
    return userNAME; 
} 

public void setUserNAME(String userNAME) { 
    this.userNAME = userNAME; 
} 

public String getYearFrom() { 
    return yearFrom; 
} 

public void setYearFrom(String yearFrom) { 
    this.yearFrom = yearFrom; 
} 

public String getYearTo() { 
    return yearTo; 
} 

public void setYearTo(String yearTo) { 
    this.yearTo = yearTo; 
} 
} 

및 검색하기위한 코드가

@Override 
    public void onChildAdded(DataSnapshot dataSnapshot, String s) { 
     // Map<String, String> msg = (HashMap<String, String>)dataSnapshot.getValue(); 
-->  ExtraProfilClass extraProfilClass=dataSnapshot.getValue(ExtraProfilClass.class); 

    // String userEmail_here=extraProfilClass.getUserEmail(); 
    //  userEmailKey = userEmail_here.substring(0, userEmail_here.length() - 10); 

이다 그래서 .. 나는 문제를 해결. 나는 올바른 노드 참조를 사용하지 않은 나의 나쁜

문제는 내가 USER1의 프로필 노드을 얻고 싶었다 것이 었습니다 (같은 Shubhank의 요청 FIX)

public static DatabaseReference mFirebaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl(constants.FIREBASE_URL+"app/authGplus/users/"); 

내가했다 그래서 뭐 내가 addChildEventListener

를 호출하고 같이 mFirebaseRef.child(UserToWhichProfileIsNeeded).child("profile").addChildEventListener(listener);

하지만 :이었다3210

이미 , 그래서 내가 refernce를하는 동안 .child("profile")를 넣을 필요가 없습니다 그것은 다음과 같이 될 것입니다 자식 노드

mFirebaseRef.child(UserToWhichProfileIsNeeded).addChildEventListener(listener);

을 의미하고 그것은 괜찮 았는데. Map<String, Object>

+0

확인이 링크 http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-로 변환 to-type-when-i-turn-json-firebase-to-java? rq = 1; –

+1

하지만 firebase는 serialization 및 역 직렬화에 잭슨을 사용하지 않습니다. –

+1

수정 사항에 대한 질문을 업데이트하는 대신 수정 답변을 게시하십시오. – Shubhank

답변

3

첫째 변환 dataSnapshot은 다음 ExtraProfilClass

Map<String, Object> map = (HashMap<String, Object>) dataSnapshot.getValue(); 
+0

나는 그것이 작동하지 않는 후에 그것을 시도했다 ... 그런 식으로 n은 길을 더 이상 지원하지 않는다. 맵을 사용한다. –

관련 문제