我有一个家庭班,可以在HomeFragment
的不同片段之间切换,该片段应显示recyclerView
public class HomeFragment extends Fragment {
public HomeFragment() {
// Required empty public constructor
}
RecyclerView recyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
recyclerView = (RecyclerView) getView().findViewById(R.id.recylerview);
ReadRss readRss = new ReadRss(getContext(),recyclerView);
readRss.execute();
return inflater.inflate(R.layout.fragment_home, container, false);
}
}
我有以下XML文件
fragment_home:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.essat.essat.HomeFragment"
>
<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/recylerview"
/>
activity_home:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.essat.essat.Home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar_layout"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/Home_Container"
></FrameLayout>
</LinearLayout>
<!-- the Side Menu specification -->
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/navigation_view"
android:layout_gravity="start"
app:menu="@menu/drawer_menu"
app:headerLayout="@layout/navigation_drawer_header"
></android.support.design.widget.NavigationView>
问题在于,当我尝试启动应用程序时,它会在第一个活动(这不是Home活动)上运行。它给了我这个错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.essat.essat, PID: 7883
java.lang.NoSuchMethodError: No static method setOnApplyWindowInsetsListener(Landroid/view/View;Landroid/support/v4/view/OnApplyWindowInsetsListener;)V in class Landroid/support/v4/view/ViewCompatLollipop; or its super classes (declaration of 'android.support.v4.view.ViewCompatLollipop' appears in /data/data com.example.essat.essat/files/instant-run/dex/slice-internal_impl-24.2.0_df0cac4e51b025b2bbe5ed8e75e4eabc0038fcbb-classes.dex)
at android.support.v4.view.ViewCompat$LollipopViewCompatImpl.setOnApplyWindowInsetsListener(ViewCompat.java:1619)
at android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener(ViewCompat.java:2924)
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:425)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:312)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:277)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.essat.essat.SplachScreen.onCreate(SplachScreen.java:13)
at android.app.Activity.performCreate(Activity.java:6550)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3077)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3233)
at android.app.ActivityThread.access$1000(ActivityThread.java:197)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6856)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
PS:SplashScreen是我的应用程序上执行的第一个Activity。
我希望有人能够弄清楚,并提前感谢你
答案 0 :(得分:0)
经过一些研究和许多尝试,我发现解决方案是将gradle依赖关系更新为最新版本! 它非常适合我:D
我希望这篇文章对其他人有用。