簡體   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