0

I'm beginning to develop and I tried following a set of tutorials on Youtube. I got really confused after trying to follow tutorial 1.8.

What happens is I launch the application (using the emulator), then it opens the application. It then goes to the splash.xml screen, which is just a background, for five seconds. Then, it's suppose to go back to MainActivity.java screen, which is the main screen. Unfortunately, after showing five seconds of the splash screen, it tells me the application has stopped.

AndroidManifest.xml:

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

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

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

</manifest>

splash.xml (which is shown for 5 seconds after opening application):

<?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:background="@drawable/minecraft_wallpaperrepeating"
    android:orientation="vertical" >    

</LinearLayout>

MainActivity.java (which is suppose to come after splash.xml, but this is where it crashes):

package com.eduardopelaez.minecraftforums;

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

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle TravisIsAwesome) {
        super.onCreate(TravisIsAwesome);
        setContentView(R.layout.splash);
        Thread logoTimer = new Thread() {
            public void run() {
                try {
                    sleep(5000);
                    Intent menuIntent = new Intent(
                            "com.eduardopelaez.minecraftforums.MAINACTIVITY");
                    startActivity(menuIntent);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                finally {
                    finish();
                }
            }
        };
        logoTimer.start();
    }

    @Override
    public boolean onCreateOptionsMenu(android.view.Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
4

2 回答 2

0

意图的目标是从现有活动开始其他活动。因此,您应该有类似启动活动的内容,并且在启动启动活动中,您向 mainActivity(2 个 java 文件)声明了您的新意图。

顺便说一句,即使如此,您似乎也犯了两个错误:

  1. 格式不正确应该是新的意图(上下文,活动名称)和你做了新的意图(“”活动名称)

  2. 您的活动 com.eduardopelaez.minecraftforums.MainActivity 不是 com.eduardopelaez.minecraftforums.MAINACTIVITY

于 2013-05-03T02:36:40.233 回答
0
Intent menuIntent = new Intent(
                                 MainActivity.this, MainActivity.class);
                startActivity(menuIntent);
于 2013-05-03T02:32:47.790 回答