Why am I getting this error "Expected resource of type raw" in Android Studio?

lastpass error
invalid response lastpass
lastpass knowledge base
lastpass error saving password
as you add passwords to lastpass where are the passwords stored
lastpass addresses
lastpass update
lastpass extension

I was trying to set the default wallpaper by using a button but for some reason when i set the InputStream in the OnCreate Method, i get this error "expected resource of type raw". I am referencing the drawable folder and using the icon.png image which is in the drawable folder. I was following the tutorials in the NewBoston Series and it seems to work fine for Travis but for some reason mine doesnt work in Android Studio. What could be the error? Thanks

Camera.java:

package com.example.user.cameraapplication;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by user on 16-08-2015.
 */
public class Camera extends Activity implements View.OnClickListener{

    ImageView iv;
    Button b1,b2;
    ImageButton img;
    Intent i;
    final static  int cameractivity = 0;
    Bitmap b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo);
        inititalize();
        InputStream is = getResources().openRawResource(R.drawable.icon);
        b = BitmapFactory.decodeStream(is);
    }

    private void inititalize() {
        iv = (ImageView)findViewById(R.id.iView1);
        img = (ImageButton)findViewById(R.id.imgbtn);
        b1 = (Button)findViewById(R.id.btn1);
        b2 = (Button)findViewById(R.id.btn2);

        b1.setOnClickListener(this);
        b2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.btn1:
                try {
                    getApplicationContext().setWallpaper(b);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case R.id.imgbtn:
                i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(i,cameractivity);

                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==RESULT_OK)
        {
            Bundle extras = data.getExtras();
            b = (Bitmap)extras.get("data");
           iv.setImageBitmap(b);

        }
    }
}

Image:

The error occurred because Android Studio expected a resource file of type raw.

Solution 1:

Create a new folder in your "res" folder called "raw", and put your icon there. The raw folder should contain all your media files of your app.

Then replace

InputStream is = getResources().openRawResource(R.drawable.icon);

with

InputStream is = getResources().openRawResource(R.raw.icon);

Solution 2:

Another solution is to do it like this. This doesn't require you to create a raw folder:

InputStream is = getResources().openRawResource(+ R.drawable.icon);

I am getting the following error message when I start up my , I am getting the following error message when I start up my computer: "There was a problem starting C:\Users\GL2814\AppData\Local\Temp\qdrofg.dll. Why am I getting this Error Message?. Learn more about error message, central difference derivative

Replace

InputStream is = getResources().openRawResource(R.drawable.icon);

With

InputStream is = getResources().openRawResource(+ R.drawable.icon);

Why am I getting an "Error: Invalid Response" message?, If you encounter this error message when you try to perform an action within your Vault (e.g., add a new site password, change an existing password, etc.) I'd like to be able to create these objects, receiving an object handle in python, and then pass these object handles to other MATLAB functions, however I am getting an 'unsupported data type return from MATLAB', despite the documentation indicating I should get a matlab.object data type.

Let's look at documentation for openRawResource

Open a data stream for reading a raw resource. This can only be used with resources whose value is the name of an asset files -- that is, it can be used to open drawable, sound, and raw resources; it will fail on string and color resources.

So the solution - leave it as it is, i. e.

InputStream is = getResources().openRawResource(R.drawable.icon);

The inspection in Android Studio is just wrong. You can add

@SuppressWarnings("ResourceType")

to hide the error.

Note

Using + R.drawable.icon just fools the inspection, because it can no longer determine which kind of resource it is.

Why am I getting an error message when I'm watching a video , You may notice an error message on your player from time to time if you've had a live stream or video running for long periods of time. Common error messages on computer are: “500 Internal Server Error.”. “Sorry, something went wrong.”. “403 Error.”. "Your browser does not currently recognize any of the video formats available".

Why am I getting error messages on Kayo?, From time to time, you may receive an error message in Kayo. This article will explain the list of error messages, and what they mean. Help me i cannot print my documents because of the (error-printing) and i'm trying to fix it but unsuccesful. Show me the right step to fix this - 6646838

I'm getting an error message when I try to activate my device on , If you get an error message when you try to activate your TV, Blu-ray player, set-​top box, or other Netflix ready device, it typically points to a network connectivity  Hi James My name is Andre Da Costa; an Independent Consultant, Windows Insider MVP and Windows & Devices for IT MVP. I'm here to help you with your problem.

WHY AM I GETTING ERROR MESSAGES? – Pure Flix Support, Please review below for some error messages you may receive and why you may be receiving them. Why am I getting "Subscription First, let's figure out where the problem is. With a little detective work, we can narrow down the cause of the problem. Open a new tab and check to see if you can load another website like google.com or mozilla.org. If you can open another site, skip down to The problem only happens with certain websites .

Comments
  • Consider this
  • Any explanation why that happens?
  • @OndrejTokar I have updated my answer with the reason. Please check it.
  • @HusseinElFeky why does '+ R.drawable.icon' fix the issue? Thanks!
  • @newbyca It somehow converts the drawable file into a raw file, without needing to create a raw folder.
  • I think as the function openRawResource is expecting an int as the argument, When we pass R.drawable.something the ide errors out that it needs a raw resource as it's able to identify that it's not a raw resource. When + R.drawable.something is used it would turn out to be an int but it cannot determine what kind of int i.e. either a drawable or raw.