Cannot lock Java compile cache as it has already been locked by this process

Viewed 557

My code does not have any runtime error but has the above compile time error I am using recyclerview Here is my code MainActivity.kt

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        recyclerView.layoutManager= LinearLayoutManager(this)
        val items=fetchData()
        val adapter=NewsListAdapter(items)
        recyclerView.adapter=adapter
    }
    fun fetchData():ArrayList<String>{
        val list=ArrayList<String>()
        for (i in 1 until 100){
            list.add("Items $i")
        }
        return list
    }
}

NewsListAdapter.kt

class NewsListAdapter(private val items: ArrayList<String>) : RecyclerView.Adapter<NewsViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NewsViewHolder {
        val view =LayoutInflater.from(parent.context).inflate(R.layout.items_news,parent,false)
        return NewsViewHolder(view)
    }

    override fun onBindViewHolder(holder: NewsViewHolder, position: Int) {
        val currentitem=items[position]
        holder.titletext.text = currentitem
    }

    override fun getItemCount(): Int {
        return  items.size
    }
}

class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val titletext: TextView =itemView.findViewById(R.id.textView)
}
1 Answers

This error usually means that previous gradle process didn't finish correctly and is still persists in memory.
For Windows, it helped me to find excessive java processes in the task manager and kill them. They usually hide under your IDE parent process.
For Linux you can do as it says here. Find these processes with:

ps -ef | grep gradle

and stop them using kill.

Related