My app keeps crashing (Fatal exception)

时光怂恿深爱的人放手 提交于 2021-01-29 11:04:15

问题


my app opens with splash screen normally but cant proceed to home screen and crashes ! i'm trying to make tablayout (there is no error in code)

this is the error through debugging :

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.foot.ws.worldcup, PID: 10249 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.foot.ws.worldcup/com.foot.ws.worldcup.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2904) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2979) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:180) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:835) Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class android.support.design.widget.AppBarLayout Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.newInstance0(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:334) at android.view.LayoutInflater.createView(LayoutInflater.java:647) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:422) at android.app.Activity.setContentView(Activity.java:2665) at com.foot.ws.worldcup.MainActivity.onCreate(MainActivity.java:19) at android.app.Activity.performCreate(Activity.java:6986) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1232) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2857) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2979) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:180) at android.app.ActivityThread.main(ActivityThread.java:6944) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:835) Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library. at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33) at android.support.design.widget.AppBarLayout.(AppBarLayout.java:158) at java.lang.reflect.Constructor.newInstance0(Native Method)  at java.lang.reflect.Constructor.newInstance(Constructor.java:334)  at android.view.LayoutInflater.createView(LayoutInflater.java:647)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)  at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:422)  at android.app.Activity.setContentView(Activity.java:2665)  at com.foot.ws.worldcup.MainActivity.onCreate(MainActivity.java:19)  at android.app.Activity.performCreate(Activity.java:6986)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1232)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2857)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2979)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1643)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:180)  at android.app.ActivityThread.main(ActivityThread.java:6944)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:835) 

and this is the main : (imports included)

public class MainActivity extends FragmentActivity {
private TabLayout tabLayout;
private AppBarLayout appBarLayout;
private ViewPager viewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tabLayout = findViewById(R.id.tablayout_id);
    appBarLayout = findViewById(R.id.appbarid);
    viewPager = findViewById(R.id.viewpager_id);
    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

    adapter.AddFragment(new FragmentQuiz(),"Quiz");
    adapter.AddFragment(new FragmentExplore(), "Explore");
    adapter.AddFragment(new FragmentStore(), "Store");

    viewPager.setAdapter(adapter);
    tabLayout.setupWithViewPager(viewPager);
}}

xml :

<LinearLayout 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="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">


<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_gravity="center"
    app:elevation="0dp"
    android:id="@+id/appbarid">

    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:src="@drawable/image" />

</android.support.design.widget.AppBarLayout>
<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabGravity="fill"
    app:tabMode="fixed"
    android:id="@+id/tablayout_id"
    app:tabTextColor="@color/tabtextcolor"
    app:tabIndicatorColor="@color/tabindicatorcolor"
    android:background="@color/tab"/>
<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/viewpager_id"
    >
</android.support.v4.view.ViewPager>

回答1:


You need to define theme in the AndroidManifest.xml for your application like:

<application
.....
        android:theme="@style/Theme">

And defined this style in values/styles.xml file like:

<style name="Theme" parent="Theme.AppCompat.Light">
.....
</style>


来源:https://stackoverflow.com/questions/51864498/my-app-keeps-crashing-fatal-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!