Cannot find Kotlin class using Java instantiation.

huangapple go评论113阅读模式
英文:

Cannot find Kotlin class using Java instantiation

问题

我有这个Kotlin类:

package com.example.project

class BasketAdapter(val context: Context) : BaseAdapter() {
    ...
}

当我尝试在我的Java代码中实例化时,我总是得到"error: cannot find symbol"错误。这是我在Java中尝试实例化类的方式:

package com.example.project
...
public class BasketFragment extends Fragment {
...
    BasketAdapter adapter = new BasketAdapter(requireContext());
    binding.listviewItems.setAdapter(adapter);
...
}

有人能解释一下问题吗?

英文:

I have this Kotlin class:

package com.example.project

class BasketAdapter(val context: Context) : BaseAdapter() {
    ...
}

When I try to instantiate from my Java code, I always get "error: cannot find symbol". This is how I try to instantiate the class in Java:

package com.example.project
...
public class BasketFragment extends Fragment {
...
    BasketAdapter adapter = new BasketAdapter(requireContext());
    binding.listviewItems.setAdapter(adapter);
...
}

Can someone explain the issue?

答案1

得分: 0

我没有找到任何解决方案。最后我将我的适配器类转换成了Java代码。

英文:

I did not find any resolution. I ended up converting my Adapter class to Java code.

huangapple
  • 本文由 发表于 2023年4月6日 22:39:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950803.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定