无法解析构造函数'Intent(xxxx.xx.java.lang.thread.Class <com.practice.mainactivity>)'

时间:2016-02-07 18:25:20

标签: android android-intent

/ *这是我的启动器活动,基本上是一个启动画面,等待5秒但是intent.pls有一些问题帮助 * /

package com.hfad.practice;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class Starting extends AppCompatActivity {

    public void start()
    {
    }
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_starting);

        Thread timer=new Thread()
        {
            public void run()
            {
                try
                {
                      sleep(5000);
                }
                catch(InterruptedException e)
                {
                    e.printStackTrace();
                }
                finally
                {

                    Intent intent=new Intent(this,MainActivity.class); /*
                    here it is showing an error thats mentioned in the title*/
                    startActivity(intent);


                }


            }

        };
        timer.start();
    }


}

1 个答案:

答案 0 :(得分:3)

更改

Intent intent=new Intent(this,MainActivity.class);

Intent intent=new Intent(Starting.this,MainActivity.class);

在您的情况下this引用Thread子类,而Intent的第一个参数是Context对象