firebase 이용한 게시판 오류

조회수 1341회
mainActivity
public class MainActivity extends AppCompatActivity {
    Button button1;
    EditText edittext1;
    EditText edittext2;
    RecyclerView listview1;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button1=(Button) findViewById(R.id.button1);
        edittext1=(EditText) findViewById(R.id.edittext1);
        edittext2=(EditText) findViewById(R.id.edittext2);

        ListView listview = (ListView) findViewById(R.id.listview1) ;

        final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,android.R.id.text1) ;
        listview.setAdapter(adapter) ;



        DatabaseReference database = FirebaseDatabase.getInstance().getReference();
        database.child("message").addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {

                Board board = dataSnapshot.getValue(Board.class);  // Board를 가져오고
                adapter.add(board.gettitle());  // adapter에 추가합니다.

            }

            @Override
            public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            }

            @Override
            public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

            }

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

            }

            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {

            }  // message 이하 child의 이벤트를 수신
        });

    }


    public void click1button(View v){
        DatabaseReference database = FirebaseDatabase.getInstance().getReference();
        Board board=new Board(edittext2.getText().toString(),edittext1.getText().toString());
        database.child("message").push().setValue(board);
    }
Board
package com.example.myapplication100;

class Board {
    String title;
    String content;

    Board(){}

    Board(String title, String content){
        this.title=title;
        this.content=content;
    }

    public Object gettitle() {return title;}
    public String getContent(){return content;}


}
[오류코드]
E/eglCodecCommon: GoldfishAddressSpaceHostMemoryAllocator: ioctl_ping failed for device_type=5, ret=-1


E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.myapplication100, PID: 6155
    com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.example.myapplication100.Board
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertBean(com.google.firebase:firebase-database@@19.3.0:435)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.3.0:231)
        at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.3.0:79)
        at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.3.0:203)
        at com.example.myapplication100.MainActivity$1.onChildAdded(MainActivity.java:74)
        at com.google.firebase.database.core.ChildEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.3.0:79)
        at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.3.0:63)
        at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.3.0:55)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

찾아도 도통 안나와서... 제가 놓친것이 있나요?ㅠ 애뮬레이터를 작동시키면 강제종료됩니다..

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)