0

I am a complete novice at Android and I am trying to add a splash screen following an online tutorial here: http://www.slideshare.net/YasmineSherif91/android-application-how-to-add-a-splash-screen-with-timer-tutorial-4

I am now getting the error Syntax error on token(s), misplaced construct(s) and I cannot for the life of me work out why. Any help much appreciated. Thanks My code is below

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash_screen);
    Thread logoTimer - new Thread (){
        public void run(){
            try{
                    int logoTimer = 0;
                    while (logoTimer<5000){
                        sleep(100);
                        logoTimer-=logoTimer+100;
                        }
                    startActivity(new Intent("com.nrobson.mot2.Clearscreen"))
                    )
                    finally(
                            finish());
        }
    };
    }
    logoTimer.start();
4

1 回答 1

3

你有很多语法错误。尝试使用:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.splash_screen);
    Thread logoTimer = new Thread() {
        public void run() {
            try {
                int logoTimer = 0;
                while (logoTimer < 5000) {
                    try {
                        sleep(100);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    logoTimer -= logoTimer + 100;
                }
                startActivity(new Intent("com.nrobson.mot2.Clearscreen"));
            } finally {
                finish();
            }
        }
    };
    logoTimer.start();
}

这是您遇到的错误(可能不完整)列表:

  • 尝试使用-而不是=
  • logoTimer.start();在你的方法体之外
  • 使用(and代替and )_finally{}
  • 睡觉时缺少try-catchInterruptedException
  • 末尾缺少分号startActivity(new Intent("com.nrobson.mot2.Clearscreen"))
  • 未对齐的括号

此外,该行:

logoTimer -= logoTimer + 100;

转换为:

logoTimer = logoTimer - (logoTimer + 100);

你确定你想要那个吗?

于 2013-03-23T15:45:57.507 回答