android - java.lang.IllegalArgumentException:没有为片段 SignFragment 的 id 找到视图
问题描述
我正在尝试单击打开 signfragment 的按钮,但出现下面提到的崩溃:java.lang.IllegalArgumentException: No view found for id 0x7f0a03ca for fragment SignFragment{e65f679 #3 id=0x7f0a03ca}
这是我的活动课
public class MainActivity extends AppcompatActivity implements SignFragment.SignPadCallback{
setContentView(R.layout.activity_ordering_main);
//on click of a button i called this method
private void openSignPad() {
Fragment fragment = SignFragment.getInstance(this);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.orderingMainContainerfragment, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
片段类
import android.app.Fragment;
public class SignFragment extends Fragment implements View.OnClickListener {
OrderingMainCallback orderingMainCallback;
private SignPadCallback callBack;
private LinearLayout signPadLayout;
private DrawView drawView;
private int padWidth;
private int padHeight;
public static Fragment getInstance(SignPadCallback callBack) {
SignFragment fragment = new SignFragment();
fragment.callBack = callBack;
return fragment;
}
}
布局文件
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/linearLayout6"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<fragment
android:id="@+id/orderingMainContainerfragment"
android:name="com.android.emobilepos.ordering.newui.OrderingMainCatalogFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:layout="@layout/fragment_ordering_main_catalog" />
</LinearLayout>
<fragment
android:id="@+id/orderDetailsfragment3"
android:name="com.android.emobilepos.ordering.newui.OrderTotalDetailsFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/fragment_order_total_details" />
</LinearLayout>
解决方案
您在 SignFragment 类中缺少 onCreateView ..
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.sign_fragment /* this will be the layout file for your fragment. */, container, false);
return view;
}
推荐阅读
- javascript - 如何使用 jQuery 启用/禁用嵌套复选框
- reactjs - 在反应上安装 quilljs-markdown
- c# - 文件夹哈希的增量更新
- amazon-web-services - AWS copilot 无法创建资源
- html - 如何将我的 Google App Engine 应用程序作为站点托管在我的域中?
- r - 同一ggplot中单独geom_line美学的单独图例
- c++ - 重载 ++ 运算符并在其后加上 ++ 时,为什么不能在重载的 cout 中传递类替换?
- swift - Swift HealthKit HKStatisticsCollectionQuery statisticsUpdateHandler 并不总是被调用
- php - Textarea 代替输入文本 API 平台
- sql - 调试 BigQuery 存储过程