无法重定向到下一页 [英] Cannot redirect to next page

查看:49
本文介绍了无法重定向到下一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Home.java代码.即使我将意图更改为(home.this,MainActivity.class),它也不会重定向到下一页:

Here is my Home.java code. It is not redirecting to next page, even if I change the intent to (home.this, MainActivity.class):

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

public class Home extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_main);
        Thread timer = new Thread() {
            public void run() {
                try{
                    sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    Intent openMainActivity = new   Intent("com.droid.mine.MainActivity");
                    startActivity(openMainActivity);
                }
            }
        };
        timer.start();}{
    }
}

这是我的MainActivity.java代码.即下一页 我收到的错误为ClassCastException:

Here is my MainActivity.java code. I.e next page I am getting the error as ClassCastException:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    Button log,sign;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        log = (Button) findViewById(R.id.register);
        sign = (Button) findViewById(R.id.linktologin);
        log.setOnClickListener((OnClickListener) this);
        sign.setOnClickListener((OnClickListener) this);
    }

    public void onClick(View v) {
        switch(v.getId()) {
        case R.id.register:
            break;
        case R.id.linktologin:
            Intent i = new Intent();
            i.setClass(MainActivity.this,Register.class);
            startActivity(i);
            break;
        }
    }
}

清单如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.droid.mine"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.droid.mine.Home"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name=".MAINACTIVITY" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>   
    </application>
</manifest>

这是logcat错误:

Here is the logcat error:

04-21 15:59:07.156: I/ApplicationPackageManager(21341): cscCountry is not German : INS
04-21 15:59:07.273: D/dalvikvm(21341): GC_EXTERNAL_ALLOC freed 78K, 47% free 2860K/5379K, external   408K/517K, paused 95ms
04-21 15:59:09.648: W/dalvikvm(21341): threadid=9: thread exiting with uncaught exception   (group=0x40018578)
04-21 15:59:09.710: E/AndroidRuntime(21341): FATAL EXCEPTION: Thread-10
04-21 15:59:09.710: E/AndroidRuntime(21341): android.content.ActivityNotFoundException: No Activity  found to handle Intent { act=com.droid.mine.MainActivity }
04-21 15:59:09.710: E/AndroidRuntime(21341):    at   android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
04-21 15:59:09.710: E/AndroidRuntime(21341):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
04-21 15:59:09.710: E/AndroidRuntime(21341):    at android.app.Activity.startActivityForResult(Activity.java:2827)
04-21 15:59:09.710: E/AndroidRuntime(21341):    at android.app.Activity.startActivity(Activity.java:2933)
04-21 15:59:09.710: E/AndroidRuntime(21341):    at com.droid.mine.Home$1.run(Home.java:21)

这是我的Register.java类

Here is my Register.java class

package com.droid.mine;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Register extends Activity implements View.OnClickListener {
Button backlog,regg;


protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    backlog = (Button) findViewById(R.id.loginn);
    regg = (Button) findViewById(R.id.signup);
    backlog.setOnClickListener(this);
}
public void onClick (View v)
{

    switch(v.getId()) {
    case R.id.loginn:
        break;
    case R.id.signup:
        Intent in = new Intent();
        in.setClass(Register.this,MainActivity.class);
        startActivity(in);
        break;
    }

} }

推荐答案

首先

更改您打算使用的位置:

Change where you intent with this:

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

第二

只需使用以下命令更新您的清单:

Just update your manifest with this:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.droid.mine.Home"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.droid.mine.MainActivity"
        android:label="@string/app_name" >

    </activity>
       <activity
        android:name="com.droid.mine.Register"
        android:label="@string/app_name" >

    </activity>     
</application>

将此用作家庭活动

package com.example.pms;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.widget.Toast;

public class SplashScreen extends Activity {        
    /*
     * The thread to process splash screen events
     */
    private Thread mSplashThread;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // splash screen view
        setContentView(R.layout.activity_splash);

        final SplashScreen mSplashScreen=this;
        /*
         * The thread to wait for splash screen events
         */
        mSplashThread =new Thread(){
            @Override
            public void run(){
                try {
                    synchronized(this){
                        // Wait given period of time or exit on touch
                        wait(3000);
                    }
                }
                catch(InterruptedException ex){                    
                }

                finish();

                // Run next activity
                startActivity(new Intent(getBaseContext(), MainActivity.class));
                new Runnable() {
                    @Override
                    public void run() {
                        mSplashThread.stop(); 
                    }
                };
            }
        };
        mSplashThread.start();   
    }
    /**
     * Processes splash screen touch events
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {    
        if(event.getAction() == MotionEvent.ACTION_DOWN)
        {
            synchronized(mSplashThread){
                mSplashThread.notifyAll();
            }
        }
        return true;
    }
}

这篇关于无法重定向到下一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆