【问题标题】:Cannot be accessed from outside package无法从外部包访问
【发布时间】:2019-05-16 12:46:19
【问题描述】:

我一直在尝试使用 githubrowsersample 对向日葵应用程序示例进行 Restfulise,因此我一直在尝试进行一些复制和粘贴。但是,我对为什么会收到此错误感到完全困惑。此特定代码是完整的复制和粘贴。

我收到的错误是:

错误:DataBoundViewHolder(T) 在 DataBoundViewHolder 中不公开; 不能从 T 是类型变量的外部包访问:T 扩展类 DataBoundViewHolder 中声明的 ViewDataBinding

而我的代码与 this 相同,而是使用这些导入:

import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.view.ViewGroup;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

我的DataBoundViewHolder代码也是复制粘贴:

import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

/**
 * A generic ViewHolder that works with a ViewDataBinding
 * @param <T> The type of the ViewDataBinding.
 */

public class DataBoundViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
    public final T binding;
    DataBoundViewHolder(T binding) {
        super(binding.getRoot());
        this.binding = binding;
    }
}

感谢您的宝贵时间

【问题讨论】:

标签: java android mvvm


【解决方案1】:

让你的班级public

    public class DataBoundViewHolder<T extends ViewDataBinding> extends RecyclerView.ViewHolder {
    ..
}

因为我想现在是package-private

【讨论】:

  • 据我所知,我会在其中添加 DataBoundViewHolder 类,你是对的,我错过了开头文本中的内容。
  • @Shade,如果有帮助请采纳)
  • 好吧,我误解了你的意思。我已将它们置于同一层次结构中,并且它们正在工作。在同一场景中,对于其他任何人来说都不那么复杂。我把它们都放在 ui/common 中,它可以工作。谢谢尤里
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-12
  • 2021-01-12
  • 1970-01-01
相关资源
最近更新 更多