我的活动代码中出现了inflater错误
我推荐这个网站,我无法得到解决方案
我的xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<fragment
android:id="@+id/projectcommends_combine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:name="com.servicebellpartner.Fragment.ProjectComments"
tools:layout="@layout/project_comments"></fragment></RelativeLayout>
我的活动代码:
public class OrderDetails extends AppCompatActivity implements View.OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order_detail);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
ProjectComments projectComments = new ProjectComments(orderid);
fragmentTransaction.add(R.id.projectcommends_combine, projectComments);
fragmentTransaction.commit();
}}
我的片段代码:
public class ProjectComments extends Fragment {
private String orderid;
public ProjectComments(String orderid){
this.orderid = orderid;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.project_comments, container, false);
return view;
}}
我在运行应用时遇到错误
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.servicebellpartner/com.servicebellpartner.Activity.OrderDetails}: android.view.InflateException: Binary XML file line #415: Error inflating class fragment
请任何人给出解决方案和解释。
答案 0 :(得分:1)
您的xml缺少相对布局的结束标记。 片段也没有公共无参数构造函数。 所以它无法通过框架实例化。