Java Fragment和旧版本的android,为什么膨胀Fragment类时出错?
我知道这方面的问题太多了,但没有一个能解决我的问题 所以。。。我的代码: 主要活动:Java Fragment和旧版本的android,为什么膨胀Fragment类时出错?,java,android,android-fragments,Java,Android,Android Fragments,我知道这方面的问题太多了,但没有一个能解决我的问题 所以。。。我的代码: 主要活动: import android.os.Bundle; import android.support.v4.app.FragmentActivity; public class MainActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { sup
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_articles);
}
}
文章片段:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ArticleFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.article_view, container, false);
}
}
news_articles.xml布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Fragment android:name="com.example.android.fragments.HeadlinesFragment"
android:id="@+id/headlines_fragment"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<Fragment android:name="com.example.android.fragments.ArticleFragment"
android:id="@+id/article_fragment"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
一片一片地尝试着。没用
舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.fragmenttestina"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.test.fragmenttestina.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我得到:
ClassNotFoundException:二进制XML文件行#6:膨胀类片段时出错
我在我的libs文件夹中找到了android-support-v4.jar及其内置路径
已解决:
对不起,我因为注意力不集中而耽误了一天。我还没有设置碎片的名称。我想这就是问题所在。抱歉占用您的时间,谢谢您。在xml中使用此选项-
<android.support.v4.app.Fragment />
在您的描述中,您为“ArticleFragment”类编写了相同的代码。我已经解决了这个问题。点击错误,对不起。@Curlyman如果你找到了完整的答案,请发布一个完整的答案,这样其他人可以从中受益。感谢你发布了这样一个完整的错误解决方案Curly,真的帮助解决了这个问题。