简体   繁体   中英

Please help. Trying to make simple tic tac toe app with android studio. getting error

Ok so I am trying to make a tic tac toe game with android studio. I'm running into an error when trying to run the app

Error:(119, 69) error: cannot find symbol variable lib_bg. 

I have searched high and low and can't figure out what the problem is. It is referring to a R.java file which is self generated which confuses me but obviously can't find these .png image files. I have confirmed these image files are in the project archive. The r.java file doesn't reference anything to these files. I'm lost please help!

       public GameView(Context context, AttributeSet attrs) {
    super(context, attrs);
    requestFocus();

    Drawable mDrawableBg = getResources().getDrawable(R.drawable.lib_bg);
    //noinspection deprecation
    setBackgroundDrawable(mDrawableBg);

    mBmpPlayer1 = getResBitmap(R.drawable.lib_cross);
    mBmpPlayer2 = getResBitmap(R.drawable.lib_circle);

The message:

Error:(119, 69) error: cannot find symbol variable lib_bg. 

looks like a compilation error.

(If you are seeing it at runtime, then you must be ignoring compilation errors and attempting to run code that doesn't compile. That is a bad idea . Fix the compilation errors before you attempt to run the code.)

The compilation error is saying that there is no variable called lib_bg . In the code you have shown us, you are referencing it here:

getResources().getDrawable(R.drawable.lib_bg);

As you say, the R class is generated automatically. In this case it is generated from your layout XML file.

I suspect that what has happened is that you have created or updated the XML file to refer to a drawable resource, but you haven't changed your Java source code to use the correct variable name for the resource.

This Android documentation page has examples showing how the XML, the resource directory and your source code are supposed to line up for a resource reference:


If the XML file does refer to the resource with the correct name, then the problem may be that you need to force your Android IDE to regenerate the "R.java" file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM