Java 类未找到膨胀片段时发现异常
我试图在我的主要活动中包含两个片段,但这会导致类未找到异常问题 第一个片段类(SearchFragment.Class) 片段的第一个xml(search_Fragment.xml) 第二个xml片段(content_fragment.xml)Java 类未找到膨胀片段时发现异常,java,android,xml,android-fragments,Java,Android,Xml,Android Fragments,我试图在我的主要活动中包含两个片段,但这会导致类未找到异常问题 第一个片段类(SearchFragment.Class) 片段的第一个xml(search_Fragment.xml) 第二个xml片段(content_fragment.xml) 主xml文件(Main.xml) 尝试以下更改: MainActivity.java应该扩展FragmentActivity 确保SearchFragment和ContentFragment正在使用import android.support.v4.
主xml文件(Main.xml)
尝试以下更改:
MainActivity.java
应该扩展FragmentActivity
SearchFragment
和ContentFragment
正在使用import android.support.v4.app.Fragment
和MainActivity.java
正在使用import android.support.v4.app.FragmentActivity
main.xml
中声明片段时使用了额外的双引号。同时将android.name更改为class<fragment
android:id="@+id/fragment1"
class="com.guru.alex.SearchFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/fragment2"
class="com.guru.alex.ContentFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment1" />
尝试以下更改:
MainActivity.java
应该扩展FragmentActivity
SearchFragment
和ContentFragment
正在使用import android.support.v4.app.Fragment
和MainActivity.java
正在使用import android.support.v4.app.FragmentActivity
main.xml
中声明片段时使用了额外的双引号。同时将android.name更改为class<fragment
android:id="@+id/fragment1"
class="com.guru.alex.SearchFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/fragment2"
class="com.guru.alex.ContentFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment1" />
尝试删除xml中片段标记中的android:name和use class:,并将片段类的完全限定名放入其中。希望有帮助。尝试删除xml片段标记中的android:name和use class:,并将片段类的完全限定名放入其中。希望有帮助。你能发布你的日志吗?你能发布你的日志吗?是的,我后来注意到了。但是谢谢,我已经解决了我的问题,我后来注意到了。但是谢谢,我已经解决了我的问题
public class ContentFragment extends Fragment {
public ContentFragment(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.content_fragment, container, false);
}
}
<?xml version="1.0" encoding="utf-8"?>
<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=".ContentFragment" >
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/fragment1"
android:name="com.guru.alex.SearchFragment”"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/fragment2"
android:name="com.guru.alex.ContentFragment”"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment1" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SlidingDrawer
android:id="@+id/slidingDrawer1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:content="@+id/content"
android:handle="@+id/handle"
android:orientation="horizontal"
android:rotation="180" >
<Button
android:id="@+id/handle"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:text=""
android:visibility="invisible" />
<RelativeLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#333"
android:orientation="vertical"
android:rotation="180" >
<TextView
android:id="@+id/tvCat"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#f37c20"
android:gravity="center"
android:text="Category"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#333" />
<ExpandableListView
android:id="@+id/elvItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tvCat"
android:animateLayoutChanges="true"
android:divider="@drawable/custom_divider"
android:dividerHeight="0dp"
android:groupIndicator="@drawable/custom_group_indicator"
android:transcriptMode="normal" >
</ExpandableListView>
</RelativeLayout>
</SlidingDrawer>
<SlidingDrawer
android:id="@+id/slidingDrawer2"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:content="@+id/content2"
android:handle="@+id/handle2"
android:orientation="horizontal" >
<Button
android:id="@+id/handle2"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:text=""
android:visibility="invisible" />
<RelativeLayout
android:id="@+id/content2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical" >
<ImageView
android:id="@+id/imgUser"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:background="#ccc"
android:contentDescription="User Profile Picture"
android:src="@drawable/default_user" />
<ExpandableListView
android:id="@+id/elvSignIn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/imgUser"
android:animateLayoutChanges="true"
android:dividerHeight="0dp"
android:groupIndicator="@drawable/custom_group_indicator"
android:indicatorLeft="180dp"
android:transcriptMode="disabled" >
</ExpandableListView>
</RelativeLayout>
</SlidingDrawer>
</FrameLayout>
</RelativeLayout>
<fragment
android:id="@+id/fragment1"
class="com.guru.alex.SearchFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<fragment
android:id="@+id/fragment2"
class="com.guru.alex.ContentFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment1" />