【问题标题】:Been staring at my code for an hour and still can't see the issue. Android - Java development [closed]盯着我的代码看了一个小时,仍然看不到问题所在。 Android - Java 开发 [关闭]
【发布时间】:2014-04-14 03:21:13
【问题描述】:

Java:

package com.example.test1;

import android.app.Activity;
import android.os.Bundle;

public class Splash extends Activity {

@Override
protected void onCreate(Bundle TravisLoveBacon) {
    // TODO Auto-generated method stub
    super.onCreate(TravisLoveBacon);
    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.example.test1.MainActivity");
                    startActivity(openStartingPoint);
                }

           }
    }


;
timer.start(); 

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/splash_background">


</LinearLayout>

编辑:非常抱歉!匆忙发布,完全忘记列出错误。

timer.start(); - 语法错误,插入“}”完成ClassBody - 标记“开始”的语法错误,此标记后应有标识符

我已经盯着我的代码看了一个小时,但找不到问题所在。我只知道这个错误是一些愚蠢的语法错误,正盯着我看。

任何帮助表示赞赏!

【问题讨论】:

  • 我想将标题编辑为有意义的内容,但是...您还没有告诉我们有关问题的任何信息
  • } 括号后面的 setContentView(R.layout.splash); 是有意的吗?
  • 您不能从主线程外部启动活动。检查这个答案stackoverflow.com/questions/6274653/…

标签: java android xml eclipse


【解决方案1】:

删除timer.start();之前的;,并删除setContentView(R.layout.splash);}行末尾的}

【讨论】:

  • 这不是问题;它结束了方法,所以程序的其余部分在创建类时运行。
【解决方案2】:

在程序末尾添加右大括号 (}) 以结束类。

【讨论】:

    猜你喜欢
    • 2022-12-21
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多