작성
·
726
0
게시글 읽기 파트에서 파이어베이스에 등록한 게시물이 나오지 않습니다.
가상머신 가동 할 때 오류는 없다고 나오며, 자취톡 접근시 바로 앱이 죽어버립니다. 앱이 죽을때2022-06-09 13:49:37.044 208-210/? E/android.system.suspend@1.0-service: Error opening kernel wakelock stats for: wakeup34: Permission denied 라는 오류가 log에 나옵니다 해결방법이 있을까요?
세번째 코드에서 선생님과 다르게 BoardListLVAdapter 가 아닌 BoardListVAdapter으로 이름을 지었습니다
첫번째 이미지 파이어베이스 데이터입니다.
첫번째 코드 BoardModel.kr입니다.
두번째 코드 FBRef.kr입니다.
세번째 코드 TalkFragmant.kr입니다.
package com.example.sololife.board
data class BoardModel (
val title : String = "",
val content : String = "",
val uid : String = "",
val time : String = ""
)
package com.example.sololife.utils
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
class FBRef {
companion object {
private val database = Firebase.database
val category1 = database.getReference("contents")
val category2 = database.getReference("contents2")
val category3 = database.getReference("contents3")
val category4 = database.getReference("contents4")
val category5 = database.getReference("contents5")
val category6 = database.getReference("contents6")
val category7 = database.getReference("contents7")
val category8 = database.getReference("contents8")
val bookmarkRef = database.getReference("bookmark_list")
val boardRef = database.getReference("board")
}
}
package com.example.sololife.fragments
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.navigation.findNavController
import com.example.sololife.R
import com.example.sololife.board.BoardListVAdapter
import com.example.sololife.board.BoardModel
import com.example.sololife.board.BoardWriteActivity
import com.example.sololife.contentsList.BookmarkRVAdapter
import com.example.sololife.contentsList.ContentModel
import com.example.sololife.databinding.FragmentTalkBinding
import com.example.sololife.utils.FBRef
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
class TalkFragment : Fragment() {
private lateinit var binding : FragmentTalkBinding
private val boardDataList = mutableListOf<BoardModel>()
private val TAG = TalkFragment::class.java.simpleName
private lateinit var boardRVAdapter: BoardListVAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_talk, container, false)
/*val boardList = mutableListOf<BoardModel>()
boardList.add(BoardModel("a", "b", "c", "d"))*/
boardRVAdapter = BoardListVAdapter(boardDataList)
binding.boardListView.adapter = boardRVAdapter
binding.writeBtn.setOnClickListener {
val intent = Intent(context, BoardWriteActivity::class.java)
startActivity(intent)
}
binding.homeTap.setOnClickListener {
it.findNavController().navigate(R.id.action_talkFragment2_to_homeFragment2)
}
binding.tipTap.setOnClickListener {
it.findNavController().navigate(R.id.action_talkFragment2_to_tipFragment2)
}
binding.bookmarkTap.setOnClickListener {
it.findNavController().navigate(R.id.action_talkFragment2_to_bookmarkFragment2)
}
binding.storeTap.setOnClickListener {
it.findNavController().navigate(R.id.action_talkFragment2_to_transactionFragment2)
}
getFBBoardData()
return binding.root
}
private fun getFBBoardData(){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (dataModel in dataSnapshot.children) {
Log.d(TAG, dataModel.toString())
val item = dataModel.getValue(BoardModel::class.java)
boardDataList.add(item!!)
}
boardRVAdapter.notifyDataSetChanged()
Log.d(TAG, boardDataList.toString())
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FBRef.boardRef.addValueEventListener(postListener)
}
}
답변 2
0
0
추가로 BoardListVAdapter.kt 코드도 올립니다
package com.example.sololife.board
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.example.sololife.R
class BoardListVAdapter(val boardList : MutableList<BoardModel>) : BaseAdapter(){
override fun getCount(): Int {
return boardList.size
}
override fun getItem(position: Int): Any {
return boardList[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
var View = convertView
if (View == null) {
View == LayoutInflater.from(parent?.context).inflate(R.layout.board_list_item, parent, false)
}
return View!!
}
앱이 죽으면서 나오는 에러 코드 입니다
2022-06-11 12:13:44.023 3804-3804/com.example.sololife E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sololife, PID: 3804
kotlin.UninitializedPropertyAccessException: lateinit property boardRVAdapter has not been initialized
at com.example.sololife.fragments.TalkFragment$getFBBoardData$postListener$1.onDataChange(TalkFragment.kt:97)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
https://drive.google.com/file/d/1GlxQ2RDO_1M87NgaSlDUqEEiqhf-uFHb/view?usp=sharing 제가 깃허브를 안써봐서 Export 한 프로젝트 올렸습니다
BoardListVAdapter 에서
View == LayoutInflater.from(parent?.context).inflate(R.layout.board_list_item, parent, false)
= 요 기호를 아래처럼 하나로 해주세요~
View = LayoutInflater.from(parent?.context).inflate(R.layout.board_list_item, parent, false)
안녕하세요 민욱님
혹시 에러 로그 전체를 보여주실 수 있으실까요?
아마 앱이 죽으면서 로그가 날아가는 경우도 있을텐데, 에러 로그를 확인하실 수 있으시면 전체를 복사해서 공유해주시면 살펴볼 수 있을 것 같습니다.
혹은, 전체 코드를 깃허브에 올려놓으시고 링크 공유해주시면 한번 실행해볼게요~