-4

So I am trying to add an image under the text at the splash screen but I get this error when I build the app Error:(26, 22) String types not allowed (at 'src' with value 'drawable/appimage.jpg').

    <ImageView
    android:padding="15dp"
    android:layout_width="350dp"
    android:layout_height="345dp"
    android:src="drawable/appimage.jpg"
    android:id="@+id/imageView"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="25dp"
    android:background="@color/black"
    android:layout="@+id/imageview"
    />

If I remove the image code , I don't get any error. Here is My splash activity code

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends AppCompatActivity {

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

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);
        final Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();
                synchronized (this) {
                    try {
                        wait(2000);

                        startActivity(new Intent(SplashActivity.this, HomeActivity.class));
                        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                        finish();

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        thread.start();
    }
}

I am a newbie android studio user so references for further learning shall be highly appreciated.

Daniel S
  • 103
  • 1
  • 8
  • Solution: Remove .jpg or .png and it will work, if doesn't just refractor and rename and try again without file extension. – Daniel S Oct 12 '17 at 18:33

3 Answers3

1

Set the src in ImageView like this:

android:src="@drawable/appimage"

You have misspelled drawable, and the .jpg should be removed.

android:src="drawable/appimage.jpg" //no path to go to

Edit - You also don't have to explicitly give the file extension to when referring to any file in resources folder.

Kartik Shandilya
  • 3,796
  • 5
  • 24
  • 42
0

Try below code...you have to rename your image goto drawable>yourimage>File>Refactor>Rename.

 android:src="drawable/appimage"
Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
0

Try this

      android: background="@drawable/appimage.jpg"

And give the color in view group

      android:background="@color/black"

layout or liner layout what ever you have