简体   繁体   English

Android:由于未知原因,应用崩溃

[英]Android: App crashes due to unknown reasons

I have an android app, in this an activity has two fragments, I haven't added any code to the fragments, here it the activity: 我有一个android应用,在这个活动中有两个片段,我没有在片段中添加任何代码,这里是活动:

schedule_settings.java schedule_settings.java

public class schedule_settings extends AppCompatActivity {

    Fragment fragment;
    Button dailyButton, weeklyButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_schedule_settings);      //The error occurs here according to log cat...

        //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        //setSupportActionBar(toolbar);

        if (getActionBar() != null) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
            getActionBar().setTitle("Schedule Settings");
            getSupportActionBar().hide();
        } else if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("Schedule Settings");
        }

        dailyButton = (Button) findViewById(R.id.scheduleSettingsDailyButton);
        weeklyButton = (Button) findViewById(R.id.scheduleSettingsWeeklyButton);

        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        //getLoaderManager().initLoader(0, null, );
    }

    public void launchWeeklyFragment(View view) {
        fragment = new schedule_settings_weekly();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.scheduleSettingsFragment, fragment);
        fragmentTransaction.commit();

        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

        dailyButton.setBackground(getResources().getDrawable(R.drawable.left_rounded_button_not_clicked));
        weeklyButton.setBackground(getResources().getDrawable(R.drawable.right_rounded_button_clicked));
    }

    public void launchDailyFragment(View view) {
        fragment = new schedule_setting_daily();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.scheduleSettingsFragment, fragment);
        fragmentTransaction.commit();

        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);

        dailyButton.setBackground(getResources().getDrawable(R.drawable.left_rounded_button_clicked));
        weeklyButton.setBackground(getResources().getDrawable(R.drawable.right_rounded_button_not_clicked));
    }
}

Here is the xml for the same, it consists of two parts the activity_schedule_settings.xml and content_schedule_settings.xml . 这是相同的xml,它由activity_schedule_settings.xmlcontent_schedule_settings.xml的两部分组成。 Here is activity_schedule_settings.xml: 这是activity_schedule_settings.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.android.smartswitch.schedule_settings">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_schedule_settings" />

</android.support.design.widget.CoordinatorLayout>

Here is the content_schedule_settings_main.xml: 这是content_schedule_settings_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.android.smartswitch.schedule_settings"
    tools:showIn="@layout/activity_schedule_settings">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:gravity="center"
            android:orientation="horizontal"
            android:padding="20dp">

            <Button
                android:id="@+id/scheduleSettingsDailyButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/left_rounded_button_clicked"
                android:onClick="launchDailyFragment"
                android:text="Daily" />

            <Button
                android:id="@+id/scheduleSettingsWeeklyButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/right_rounded_button_not_clicked"
                android:onClick="launchWeeklyFragment"
                android:text="Weekly" />

        </LinearLayout>

        <fragment
            android:id="@+id/scheduleSettingsFragment"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>

</ScrollView>

The error occurs in marked java part. 该错误发生在标记的 Java部分中。 Here is the log cat trace, I don't know what to do as it marks the part where I actually assign the xml file to java as the error: 这是日志猫跟踪,我不知道该怎么办,因为它标记了我实际将xml文件分配给java的部分作为错误:

04-22 16:55:51.045 12130-12130/com.example.android.smartswitch E/AndroidRuntime: FATAL EXCEPTION: main
                                                                             Process: com.example.android.smartswitch, PID: 12130
                                                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.smartswitch/com.example.android.smartswitch.schedule_settings}: android.view.InflateException: Binary XML file line #43: Binary XML file line #43: Error inflating class fragment
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:148)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                              Caused by: android.view.InflateException: Binary XML file line #43: Binary XML file line #43: Error inflating class fragment
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                 at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288)
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143)
                                                                                 at com.example.android.smartswitch.schedule_settings.onCreate(schedule_settings.java:25)
                                                                                 at android.app.Activity.performCreate(Activity.java:6237)
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                              Caused by: android.view.InflateException: Binary XML file line #43: Error inflating class fragment
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                 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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                                                                                 at com.example.android.smartswitch.schedule_settings.onCreate(schedule_settings.java:25) 
                                                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                              Caused by: java.lang.NullPointerException
                                                                                 at java.lang.VMClassLoader.findLoadedClass(Native Method)
                                                                                 at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:362)
                                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:499)
                                                                                 at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                 at android.support.v4.app.Fragment.isSupportFragmentClass(Fragment.java:459)
                                                                                 at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3321)
                                                                                 at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
                                                                                 at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
                                                                                 at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
                                                                                 at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
                                                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) 
                                                                                 at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                 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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:288) 
                                                                                 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:143) 
                                                                                 at com.example.android.smartswitch.schedule_settings.onCreate(schedule_settings.java:25) 
                                                                                 at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                 at android.os.Looper.loop(Looper.java:148) 
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                 at java.lang.reflect.Method.invoke(Native Method) 
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

I'm new to android and this error is giving me lots of problems, I tried to google it but couldn't find anything relevant. 我是Android新手,此错误给我带来了很多问题,我尝试在Google上进行搜索,但找不到任何相关内容。 Please help... 请帮忙...

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.smartswitch/com.example.android.smartswitch.schedule_settings}: android.view.InflateException : Binary XML file line #43: Binary XML file line #43 : Error inflating class fragment java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.android.smartswitch / com.example.android.smartswitch.schedule_settings}: android.view.InflateException :二进制XML文件行#43:二进制XML文件line #43 :错误夸大class片段

You should add the class name to your <fragment /> in content_schedule_settings XML. 您应该在content_schedule_settings XML中将class名称添加到<fragment />中。

Try this: 尝试这个:

<fragment
    android:id="@+id/scheduleSettingsFragment"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    class="com.example.android.smartswitch.schedule_settings_weekly" />

Hope this will work perfectly. 希望这将完美地工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot应用程序因未知原因崩溃 - Spring Boot app crashes by unknown reasons 由于添加了布局,Android App崩溃了 - Android App crashes due to adding a layout 应用服务器崩溃的主要原因 - top reasons why an app server crashes 由于没有@Subcribe方法,Android EventBus应用程序在发布模式下崩溃 - Android EventBus app crashes in release mode due to no @Subcribe methods Android 聊天应用程序由于 java.util.ConcurrentModificationException 而崩溃 - Android chat app crashes due to java.util.ConcurrentModificationException Android应用程序因RecyclerView而崩溃 - Android application crashes due to RecyclerView android-由于listview应用程序崩溃 - android - Application crashes due to the listview 应用质量Android与iPhone? 背后的原因是什么? - App quality Android vs IPhone ? The Reasons behind it? Android 将 minifyEnabled 设置为 true 并将 shrinkResources 设置为 true 时,由于 NullPointerException,应用程序在发布版本中崩溃 - Android App crashes in the release build due to NullPointerException when setting minifyEnabled to true and shrinkResources to true 由于IllegalArgumentException导致应用程序崩溃:com.android.internal.policy.impl.PhoneWindow - App crashes due to IllegalArgumentException : com.android.internal.policy.impl.PhoneWindow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM