【问题标题】:setContentView not recognizing .xml pagesetContentView 无法识别 .xml 页面
【发布时间】:2012-04-06 02:56:39
【问题描述】:

我在我的应用程序的开头添加了一个起始页,它持续了 5 秒,但是当我这样做时,它在 setContentView(R.layout.splash); 旁边放了一个小“x”。并且有一个 xml 文件,所以我不知道为什么它不起作用。我加粗的线是我遇到问题的线。

package com.jslsoftware;

import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class ILearnSignActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread logoTimer = new Thread(){
    public void run(){
        try{
            sleep(5000);
            Intent menuIntent = new Intent("com.jslsoftware.MENU");
            startActivity(menuIntent);              
        }           
        finally{
            finish();               
        }
    }        
    };
    logoTimer.start();          
   }
}

【问题讨论】:

    标签: android xml splash-screen


    【解决方案1】:

    检查你的导入它不应该是

    android.R;
    

    但是

    import com.jslsoftware.R;
    

    【讨论】:

      【解决方案2】:

      检查资源文件夹中是否有任何错误,如可绘制、字符串和布局等。如果有错误,android 无法创建 gen 文件夹。并查看 import android.R.

      【讨论】:

        【解决方案3】:

        构建 >> 清洁项目

        重新启动您的 Android Studio / Eclipse

        【讨论】:

          【解决方案4】:

          Scott,如果您使用 Eclipse:

          在文件树中选择您的项目,然后转到顶部的项目菜单 -> 清理

          这通常有助于重新组装 R 文件并将其与项目重新链接。

          【讨论】:

            【解决方案5】:

            我遇到了同样的问题。我删除了这个:

             import android.R;
            

            并替换为

             import com.(ur package).R;
            

            成功了。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多