8 Replies - 1214 Views - Last Post: 03 September 2013 - 10:02 PM

#1 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 10:15 AM

Trying to program for android. I created a blueball.png image and copied it into the drawable-hdpi folder through eclipse. I'm trying to set up some code to a animation to run. I tried deleting the R.java file and doing a clean, but same issue. I'm using it off a youtube tutorial so it should work.
             package com.example.drawball;

             import android.app.Activity;
             import android.content.Context;
             import android.graphics.Bitmap;
             import android.graphics.BitmapFactory;
             import android.graphics.Canvas;
             import android.os.Bundle;
             import android.view.View;

        public class MainActivity extends Activity {

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


	public class drawingTheBall extends View {
			
			Bitmap bball;
			int x, y;
			
			public drawingTheBall (Context context) {
				super(context);
				bball = BitmapFactory.decodeResource(getResources(), R.drawable.blueball.png);
				x = 0;
				y = 0;
			}
			protected void onDraw (Canvas canvas){
				super.onDraw(canvas);
				if (x < canvas.getWidth()){
					x+=10;}
			else{
				x = 0;
				}
				if (x >canvas.getHeight()){
					y+=10; }
				else {
					y=0; }
				
			
				
				x+=10;
				y+=10;
				
				
			}
		}

	}


This post has been edited by macosxnerd101: 21 June 2013 - 11:30 AM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: the primitive type int of R.drawable cannot be resolved

#2 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 10:41 AM

took off the png at the end and it fixed it. But I'm now getting blueball cannot be resolved or is not a field.
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 11:33 AM

Moved to Android. Please remember to use code tags: :code:.

Try importing the auto-generated R class for your project, rather than the API android.R class.
Was This Post Helpful? 0
  • +
  • -

#4 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 12:17 PM

View Postmacosxnerd101, on 21 June 2013 - 11:33 AM, said:

Moved to Android. Please remember to use code tags: :code:/>/>.

Try importing the auto-generated R class for your project, rather than the API android.R class.


The primitive type of R.drawable does not have a field blueball.

And I imported my project's R.

It said the same thing for just R.drawable if it's in the BitmapFactory.decoderesource, but when the pop up fixer came up, it had a solution to create a field in the R file, so I did that and the error for R.drawable disappeared.

but if I add blueball onto the end of it, it still doesn't recogize it, like it doesn't know its in the folder. I tried deleting the blueball out and putting it in again but no go.

This post has been edited by Crewd: 21 June 2013 - 12:25 PM

Was This Post Helpful? 0
  • +
  • -

#5 Crewd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 25-April 13

Re: the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 01:05 PM

I got rid off the errors. Closed out the app, opened it again. R file doesn't need to be imported, deleted the R.java file again, and it worked.

I feel like sometimes it just randomly does whatever it wants to, even though that's not the case, but I swear I did that already. Maybe not all together?, who knows.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: the primitive type int of R.drawable cannot be resolved

Posted 21 June 2013 - 01:12 PM

Sometimes a clean and build takes care of some problems like this. That's probably what happened when you restarted things.
Was This Post Helpful? 0
  • +
  • -

#7 rahul.r4  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 56
  • Joined: 11-August 13

Re: the primitive type int of R.drawable cannot be resolved

Posted 30 August 2013 - 05:05 AM

View Postmacosxnerd101, on 21 June 2013 - 01:12 PM, said:

Sometimes a clean and build takes care of some problems like this. That's probably what happened when you restarted things.


If you see such errors related to R.Java like all the references are showing as error and setcontentview also showing error.
Check the target of your android by right click project ->properties. Set it to API greater than 8.
Clean the project
Restart Eclipse.
It will work
Was This Post Helpful? 0
  • +
  • -

#8 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,533
  • Joined: 29-July 11

Re: the primitive type int of R.drawable cannot be resolved

Posted 03 September 2013 - 07:36 PM

This error has nothing to do with the API level...
Was This Post Helpful? 0
  • +
  • -

#9 rahul.r4  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 56
  • Joined: 11-August 13

Re: the primitive type int of R.drawable cannot be resolved

Posted 03 September 2013 - 10:02 PM

View Postfarrell2k, on 03 September 2013 - 07:36 PM, said:

This error has nothing to do with the API level...


It does. sometimes when i import project the api level is set to 3 and all these errors show up. i just change the api level to 15 or 16, clean the project and all the errors are gone
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1