Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure retrieving resources

I created a simple app and set Background of LinearLayout to an image. when i run it, don't show background image. i see this line of log:

W/PackageManager﹕ Failure retrieving resources for vania.backgroundtest: Resource ID #0x0

why can't show background image? This is my Layout code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@drawable/backimage"
    >
</LinearLayout>

This is my Java code:

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

and this is manifest:

  <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:screenOrientation="landscape"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

i used a .jpg image with 1920*1080 (412 KB)

like image 382
mSafdel Avatar asked Oct 21 '15 09:10

mSafdel


1 Answers

You should use the android:backgroundproperty of the LinearLayout

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/myimage"
        android:orientation="vertical" >

        <!-- More elements --> 

</LinearLayout>

Where myimage is a correct image in the res/drawable directory. You can find more details in the documentation

like image 141
ThomasThiebaud Avatar answered Sep 21 '22 09:09

ThomasThiebaud