gpt4 book ai didi

java - Android 细节 fragment

转载 作者:行者123 更新时间:2023-12-02 12:28:12 28 4
gpt4 key购买 nike

如果我尝试在 View 中打开 DeatilFragement,我的应用程序崩溃并收到以下错误:

Caused by: 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) annotation. at 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) at 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);
}
}

最佳答案

这是你的错误:

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;

问题是 fragment 布局中没有具有属性 android:id="@+id/login" 的 View 。添加此 View (或更正其 id 属性),或将您的 View 标记为 @Nullable

关于java - Android 细节 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45394839/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com