我的应用程序崩溃,如果我尝试在我的视图中打开DeatilFragement,则会出现以下错误:
引起:java.lang.IllegalStateException:必需的视图'login' 未找到字段“login”的ID 2131558406。如果这个观点是 可选添加'@Nullable'(字段)或'@Optional'(方法)注释。 在butterknife.internal.Utils.findRequiredView(Utils.java:92)at butterknife.internal.Utils.findRequiredViewAsType(Utils.java:104)at de.dev.myapp.ui.quote.ArticleDetailFragment_ViewBinding。(ArticleDetailFragment_ViewBinding.java:23) at java.lang.reflect.Constructor.newInstance0(Native Method)at java.lang.reflect.Constructor.newInstance(Constructor.java:430)at butterknife.ButterKnife.createBinding(ButterKnife.java:199)at butterknife.ButterKnife.bind(ButterKnife.java:172)at de.dev.myapp.ui.base.BaseFragment.inflateAndBind(BaseFragment.java:29) 在 de.dev.myapp.ui.quote.ArticleDetailFragment.onCreateView(ArticleDetailFragment.java:69)
ArticleDetailFragment_ViewBinding引用此行:
public ArticleDetailFragment_ViewBinding(ArticleDetailFragment target, View source) {
this.target = target;
target.login = Utils.findRequiredViewAsType(source, R.id.login, "field 'login'", TextView.class);
BaseFragment引用这一行:
public View inflateAndBind(LayoutInflater inflater, ViewGroup container, int layout) {
View view = inflater.inflate(layout, container, false);
ButterKnife.bind(this, view); // this line
LogUtil.logD(TAG, ">>> view inflated");
return view;
}
ArticleDetailFragment引用了这一行:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflateAndBind(inflater, container, R.layout.fragment_article_detail); // this line
if (!((BaseActivity) getActivity()).providesActivityToolbar()) {
// No Toolbar present. Set include_toolbar:
((BaseActivity) getActivity()).setToolbar((Toolbar) rootView.findViewById(R.id.toolbar));
}
if (dummyItem != null) {
loadBackdrop();
collapsingToolbar.setTitle(dummyItem.title);
author.setText(dummyItem.author);
quote.setText(dummyItem.content);
}
return rootView;
}
这就是我选择每个项目移动到详细信息页面的方式
@Override
public void onItemSelected(String id) {
if (twoPaneMode) {
// Show the quote detail information by replacing the DetailFragment via transaction.
ArticleDetailFragment fragment = ArticleDetailFragment.newInstance(id);
getFragmentManager().beginTransaction().replace(R.id.article_detail_container, fragment).commit();
} else {
// Start the detail activity in single pane mode.
Intent detailIntent = new Intent(this, ArticleDetailActivity.class);
detailIntent.putExtra(ArticleDetailFragment.ARG_ITEM_ID, id);
startActivity(detailIntent);
}
}
答案 0 :(得分:1)
这是你的错误:
java.lang.IllegalStateException:
Required view 'login' with ID 2131558406 for field 'login' was not found.
If this view is optional add '@Nullable' (fields) or '@Optional' (methods)
这意味着您的ArticleDetailFragment
极有可能包含这些行:
@BindView(R.id.login)
private View login;
问题是片段布局中没有属性android:id="@+id/login"
的视图。添加此视图(或更正其ID属性),或将View
标记为@Nullable
。