0

I'm still new to Java, and I'm stuck.

When I use this line appView.setBackgroundColor(Color.TRANSPARENT); in my mainactivity.java file, an error shows up as "Color cannot be resolved to a variable".

I understand that "Color" has to be defined in a file somewhere in my Android project but I don't know where, or what other commands/elements/etc. need to go along with it.

I tried creating a style (assuming that was what I was supposed to do), but it didn't work, because of my limited Android/Java knowledge. My Google searches were fruitless, so that is why I am here.

Below is what my mainactivity.java file contains.

package com.ABC_Co.Twirly;

/* import android.app.Activity; */
import android.os.Bundle;
import org.apache.cordova.*;

public class util_952 extends DroidGap
{
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");
    appView.setBackgroundColor(Color.TRANSPARENT);
}
}
Jens Mühlenhoff
  • 14,565
  • 6
  • 56
  • 113
Krang
  • 53
  • 2
  • 10
  • 5
    Add `import android.graphics.Color;` as import statement – Pankaj Kumar Mar 18 '14 at 17:07
  • Please refer to http://stackoverflow.com/questions/6590827/r-cannot-be-resolved-to-a-variable previously answered – Mouhamed Ndiaye Mar 18 '14 at 17:10
  • Do you use Eclipse or some other IDE? Eclipse is good at figuring things like this out, and figuring out what you need to import and adding the `import` statement for you. Don't know about other IDEs. If you're going to be doing a lot of Android programming, it's well worth the effort to learn to use one IMO. – ajb Mar 18 '14 at 17:10
  • possible duplicate of [R cannot be resolved - Android error](http://stackoverflow.com/questions/885009/r-cannot-be-resolved-android-error) – Mouhamed Ndiaye Mar 18 '14 at 17:12
  • @Pankaj Kumar, I am also kind of new to Stack Overflow, and I don't know how to give you credit for your answer (since you were the first one) because it shows up as a comment. Thanks to everyone else for your replies. I looked at "R cannot be resolved...", but it was just over my head. – Krang Mar 18 '14 at 19:36
  • @Br0therzS0ul This is not at all the same question. When the error is "SomeClass cannot be resolved", it just needs to be imported; but "R cannot be resolved" is a special case that is caused by other problems, because `R` is a special class in Android. – ajb Mar 18 '14 at 23:15
  • I made a mistake on the specific link then Check this one out http://stackoverflow.com/questions/6590827/r-cannot-be-resolved-to-a-variable -- Please confirm if its the same, the asker could then refer to it – Mouhamed Ndiaye Mar 19 '14 at 13:36

3 Answers3

1

Since noone has answered yet:

"Color cannot be resolved to a variable."

That error means, that you need to import the class Color into your java file:

import android.graphics.Color;
// other imports

public class YourClass {

    // your code
}
Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
0

You need to import android.graphics.Color to your application. If you want to define your own custom colors, you need to create a file called colors.xml (the name can be anything - just being intuitive) under the values folder in the res directory. The root element of colors.xml will be resources. You can then implement your own custom colors here and refer to them using R.color.some_color.

ucsunil
  • 7,378
  • 1
  • 27
  • 32
-1

In android under values folder, create a xml file color.xml The root tag in that file will be resources. When you want to access the colors in an activity, android:background="@color/black" or whichever color will be defined in the colors.xml

artist
  • 6,271
  • 8
  • 25
  • 35