繁体   English   中英

(R.layout.splash); 飞溅无法解决或不是字段

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

我正准备在eclipse上制作我的第一个Android应用程序,并且遇到了问题。 基本上,我无法解决启动错误或不是字段错误。 该代码在10分钟前有效。 以下链接是我的保管箱中该项目的链接。 如果需要的话,您可以测试一些理论。 https://www.dropbox.com/sh/1sg8p9uvjbolqxx/AADcMiPWB_JVEysb01B_hUtBa以下是Java端代码的副本。

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>

验证布局初始文件中是否没有错误。 可能是该项目未构建R,因为您在某些XML文件中存在错误。 尝试找到它并清除项目。

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);
}

我想通了,谢谢你们。 当我撤消输入的代码时,我发现以下内容弄乱了所读取的布局。 导入android.R;

谢谢大家的帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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