2017-09-13 62 views
1

每當我進入我的新活動時,在其OnCreate()方法中的SetContentView()方法發生錯誤。SetContentView()錯誤:Android.Views.InflateException

錯誤狀態:Unhandled Exception: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class <unknown> occurred

我擡頭看向其他類似的問題和他們的答案,但他們的解決方案不適合我。爲佈局

<?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> 

我的XML代碼的問題主要發生後,我加入了seekerbar和TextView的(在XML的底部)。

的logcat(活動前幾行發生):

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> 

此外,我使用Visual Studio 2017年爲我的IDE。

+0

分享你的日誌貓 –

+0

添加完整的日誌貓 –

+0

你的imageview源文件有太大的MB。 –

回答

3

它與您的守護程序無法縮放和轉換以及發生系統內存泄漏的映像有關。

嘗試縮小所有繪圖和圖像源的大小。這將解決memort問題。

+0

希望幫助:) –

+0

這有很大的幫助,我也有一些位於周圍的Bitmap對象佔用了大量的空間,我刪除了。 – WQYeo

+0

相關提示:) –

相關問題