Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SetContentView()错误:Android.Views.InflateException_Android_Xml_Visual Studio_Xamarin_Xamarin.android - Fatal编程技术网

SetContentView()错误:Android.Views.InflateException

SetContentView()错误:Android.Views.InflateException,android,xml,visual-studio,xamarin,xamarin.android,Android,Xml,Visual Studio,Xamarin,Xamarin.android,每当我转到新活动时,其OnCreate()方法中的SetContentView()方法都会发生错误 错误状态为:未处理的异常:Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:发生错误膨胀类 我仰望着其他类似的问题和他们的答案,然而他们的解决方案并不适合我 布局的XML代码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http:

每当我转到新活动时,其
OnCreate()
方法中的
SetContentView()
方法都会发生错误

错误状态为:
未处理的异常:Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:发生错误膨胀类

我仰望着其他类似的问题和他们的答案,然而他们的解决方案并不适合我

布局的XML代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minWidth="25px"
    android:id="@+id/testing"
    android:minHeight="25px">
    <Toolbar
        android:minHeight="?android:attr/actionBarSize"
        android:background="?android:attr/colorPrimary"
        android:minWidth="25px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/toolbar1">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/linearLayout1">
            <ImageView
                android:src="@drawable/arrow_left"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:id="@+id/playMusicBackBtn" />
            <TextView
                android:text="Song Title"
                android:layout_marginLeft="10dp"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center"
                android:layout_gravity="center"
                android:id="@+id/nowPlayingSongTitle" />
            <Space
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:id="@+id/space1" />
            <ImageView
                android:src="@drawable/settings_icon"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:id="@+id/playMusicSetting" />
        </LinearLayout>
    </Toolbar>
<!--Song Image-->
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:id="@+id/songImage"
        android:layout_margin="25dp" />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout3">
        <TextView
            android:text="Song Title - Song Artist"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_marginLeft="15dp"
            android:layout_gravity="center"
            android:layout_height="match_parent"
            android:id="@+id/songTitleDisplay" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/space1" />
        <ImageView
            android:src="@drawable/favorite_off"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/addFavoriteBtn"
            android:layout_marginRight="20dp" />
    </LinearLayout>
<!--Interactive Buttons that deal with the Media player-->
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/linearLayout2"
        android:weightSum="4">
        <ImageView
            android:layout_marginLeft="20dp"
            android:src="@drawable/shuffle_off"
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/shuffleBtn" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/space1" />
        <ImageView
            android:src="@drawable/play_prev"
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/playPrevBtn" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/space1" />
        <ImageView
            android:src="@drawable/play"
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/playPauseBtn" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/space1" />
        <ImageView
            android:src="@drawable/play_next"
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:id="@+id/playNextBtn" />
        <Space
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:id="@+id/space1" />
        <ImageView
            android:src="@drawable/repeat_off"
            android:layout_width="55dp"
            android:layout_height="55dp"
            android:layout_marginRight="20dp"
            android:id="@+id/repeatBtn" />
    </LinearLayout>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_margin="5dp"
        android:layout_height="wrap_content"
        android:id="@+id/musicSeekerBar" />
    <TextView
        android:text="Current - Max"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_marginTop="5dp"
        android:id="@+id/musicDuration" />
</LinearLayout>

问题主要发生在我添加seekerbar和textview(在XML的底部)之后

Logcat(事件发生前的几行):

09-13 09:09:28.332 I/art(4650):将目标GC堆从283MB钳制到256MB
09-13 09:09:28.332 I/art(4650):Alloc并发标记扫描GC释放了3(72B)个AllocSpace对象,0(0B)个LOS对象,1%空闲,251MB/256MB,暂停597us总计35.921ms
09-13 09:09:28.332 I/art(4650):强制收集13MB分配的软引用
09-13 09:09:28.332 I/art(4650):启动阻塞GC分配
09-13 09:09:28.365 I/art(4650):将目标GC堆从283MB钳制到256MB
09-13 09:09:28.365 I/art(4650):Alloc并发标记扫描GC释放3(72B)个AllocSpace对象,0(0B)个LOS对象,1%空闲,251MB/256MB,暂停500us总计32.744ms
09-13 09:09:28.365 W/art(4650):抛出OutOfMemoryError“分配14107548字节分配失败,4666448个空闲字节和4MB直到OOM”
09-13 09:09:28.366 D/skia(4650):---缩放位图的分配失败
未处理的异常:
Android.Views.InflateException:二进制XML文件行#1:二进制XML文件行#1:膨胀类时出错

另外,我正在使用Visual Studio 2017作为我的IDE。

这与您的守护进程无法缩放和转换的图像有关,并且会发生系统内存泄漏


试着缩小所有可绘图和图像源的大小。这将解决内存不足的问题

共享您的日志添加完整的日志您的imageview源文件的MB太大。这与您的守护程序无法缩放和转换的图像有关,并且出现系统内存泄漏。希望这有帮助:)这很有帮助,我还有一些位图对象,它们也占用了大量空间,我删除了。很高兴知道:)
    09-13 09:09:28.332 I/art     ( 4650): Clamp target GC heap from 283MB to 256MB
09-13 09:09:28.332 I/art     ( 4650): Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 251MB/256MB, paused 597us total 35.921ms
09-13 09:09:28.332 I/art     ( 4650): Forcing collection of SoftReferences for 13MB allocation
09-13 09:09:28.332 I/art     ( 4650): Starting a blocking GC Alloc
09-13 09:09:28.365 I/art     ( 4650): Clamp target GC heap from 283MB to 256MB
09-13 09:09:28.365 I/art     ( 4650): Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 1% free, 251MB/256MB, paused 500us total 32.744ms
09-13 09:09:28.365 W/art     ( 4650): Throwing OutOfMemoryError "Failed to allocate a 14107548 byte allocation with 4666448 free bytes and 4MB until OOM"
09-13 09:09:28.366 D/skia    ( 4650): --- allocation failed for scaled bitmap
Unhandled Exception:

Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class <unknown>