gpt4 book ai didi

java - 膨胀 fragment 时出错

转载 作者:行者123 更新时间:2023-12-01 11:17:08 27 4
gpt4 key购买 nike

我有一个 fragment ,我像下面一样对其进行膨胀,但它给出了运行时错误:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View jobsView = inflater.inflate(R.layout.fragment_job_information, container, false);
textView = (TextView) jobsView.findViewById(R.id.textView);


if (jobInfo == null) {
EmployerHistory jobsQuery=new EmployerHistory();
jobInfo = jobsQuery.getJobInfo(employerName, position);
}

textView.setText(jobInfo.get("jobName").toString());

return jobsView;
}

其对应的布局为:

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/jobInfoFragment">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ankit.job_depot.employer.view.JobInformation">


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</fragment>

实际上,我已经在带有 ListView 的 fragment 上,当用户单击 ListView 的元素时,该 fragment 需要被新 fragment 更改,在我的新 fragment 中,我有:升

istViewJobHistory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
JobInformation newFragment = new JobInformation();
android.support.v4.app.FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.listViewJobHistory, newFragment);
transaction.addToBackStack(null);
transaction.commit();
}

});

我遇到以下异常:

07-28 18:49:39.681 14474-14474/com.example.ankit.job_depot E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.ankit.job_depot, PID: 14474 android.view.InflateException: Binary XML file line #1: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763) at android.view.LayoutInflater.inflate(LayoutInflater.java:482) at android.view.LayoutInflater.inflate(LayoutInflater.java:414) at com.example.ankit.job_depot.employer.view.JobInformation.onCreateView(JobInformation.java:45) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)

最佳答案

我认为你的主要 Activity 应该扩展 FragmentActivity

import android.support.v4.app.FragmentActivity;

关于java - 膨胀 fragment 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31689082/

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