xml cannot be resolved to a field

56 Views Asked by At

I keep getting an error saying my xml file cannot be resolved to a field. I found answers saying to delete the import R statement which I have done, but this just brings up another error saying R cannot be resolved to a variable. It seems like I am doomed whether or not I use the import statement. Any advice?

Here's the code

public class VirtualGallery extends Activity {

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

    Handler x = new Handler();
    x.postDelayed(new SplashHandler(), 5000);   
}

class SplashHandler implements Runnable{
    public void run(){
        Intent myIntent = new Intent(VirtualGallery.this, Main.class);
        startActivity(myIntent);
    }
}

}

here's the splash xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#393131" >

<ImageView
android:id="@+id/museum_logo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/museum_logo" />

</RelativeLayout>
2

There are 2 best solutions below

2
On BEST ANSWER

Make sure you have imported your.package.R not android.R. Then look for error(s) in your res directory. It seems that somewhere in your res directory you have an error that prevents regenerating R class. Solve that error and clean your project.

0
On

I had the same problem, fixed it by doing a project clean