Android XML File java.lang.nullpointerexception

后端 未结 3 1856
迷失自我
迷失自我 2021-01-21 04:59

I am building a brand new android project. It\'s not my 1st android app so I\'m much more frustrated not being able to get rid of this error...

I use an XML File, which

相关标签:
3条回答
  • 2021-01-21 05:44

    Because the drawable that's not showing up is itself inside a RelativeLayout, you need to put some position attributes in the cadremenu layout so that Android knows where to place it. For example, try:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="monteil.gaming.hundredious.MainActivity" >
    
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/fondipad"
        android:contentDescription="@string/FondDesc"
    
        />
    
    <RelativeLayout 
        android:layout_height="300dp" 
        android:layout_width="fill_parent"
        **android:layout_alignParentTop="true"**
        android:background="@drawable/cadremenu">
    
    </RelativeLayout> 
    </RelativeLayout>
    
    0 讨论(0)
  • 2021-01-21 05:48

    As @laato suggested, I checked my drawable/cadremenu file. I copied/pasted/overwrited the file in my project and then everything worked fine ! I actually had the same problem with all my other resources, like if my resources folder had been corrupted or something like that.

    Thank you guys Hoping that someone will find help here someday

    0 讨论(0)
  • 2021-01-21 05:50

    This exception usually occurs due to corrupt drawables. Make sure you are able to open and view all the drawable you have linked.

    enter image description here

    If you happen to see any error message of this sort or are unable to view your drawable then try replacing it again with the original file or if you have downloaded it then try re-downloading it.

    0 讨论(0)
提交回复
热议问题