简体   繁体   中英

(R.layout.splash); splash cannot be resolved or is not a field

I'm in the middle of making my first Android app on eclipse, and I am running into a problem. Basically I'm getting a splash cannot be resolved or is not a field error. The code was working 10 min ago. The following link is to this project in my dropbox. That away if you want, you can test some theories out on it. https://www.dropbox.com/sh/1sg8p9uvjbolqxx/AADcMiPWB_JVEysb01B_hUtBa The following is a copy of the code the Java side.

public class Splash extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread timer = new Thread() {
            public void run() {
                try{
                    sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    Intent openStartingPoint = new Intent("com.techreviewsandhelp.carteretcountyhistoryguide.MAINACTIVITY");
                    startActivity(openStartingPoint);
                }
            }
        };
        timer.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

}

XML

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="schemas.android.com/apk/res/android"; 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:id="@+id/splash"> 
    <ImageView android:id="@+id/imageView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/trh" /> 
</LinearLayout>

Verify if you dont have erros in the layout splash file. Probably the project is not building the R because you have an error in some XML file. Try to find it and clear the project.

Try to replace this code:

import android.os.Handler;


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

   new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
         Intent openStartingPoint = new Intent(Splash.this,MAINACTIVITY.class);
         startActivity(openStartingPoint);
      }
   },5000);
}

I figured it out thanks to you guys. When I was undoing the code you had me put in, I found out the following was messing up the layout read. import android.R;

Thanks for everyones help.

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