【问题标题】:"Unfortunately (my app) has Stopped" error when trying to run my application尝试运行我的应用程序时出现“不幸的是(我的应用程序)已停止”错误
【发布时间】:2013-05-28 09:58:40
【问题描述】:

(Home.java),我正在尝试创建一个加载屏幕,最终导致该页面 (Home.java.)

package com.androidpeople.splash;

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


public class VirtualSkiInstructor extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView textView = new TextView(this);
        textView.setText("Main Activity");
        setContentView(textView);
    }
}

加载屏幕 (SplashScreen.java)。这是创建启动画面和加载页面的代码

package com.androidpeople.splash;

import your.custom.splash.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class SplashScreen extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

final int welcomeScreenDisplay = 3000;
/** create a thread to show splash up to splash time */
Thread welcomeThread = new Thread() {

    int wait = 0;

    @Override
    public void run() {
        try {
            super.run();

                                        while (wait < welcomeScreenDisplay) {
                    sleep(100);
                    wait += 100;
                }
            } catch (Exception e) {
                System.out.println("EXc=" + e);
            } finally {

                startActivity(new Intent(SplashScreen.this,
                VirtualSkiInstructor.class));
                finish();
            }
        }
    };
    welcomeThread.start();

}
}

(splash.xml)

<LinearLayout android:id="@+id/LinearLayout01"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:gravity="center" android:background="#6B8AAD">
 <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
 android:layout_height="wrap_content" android:textSize="18sp"
 android:textStyle="bold" android:textColor="#fff"></TextView>
 </LinearLayout>

(字符串.xml)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Compass</string>
    <string name="app_name">Compass</string>
</resources>

【问题讨论】:

    标签: android eclipse android-emulator


    【解决方案1】:

    添加以下代码以将 VirtualSkiInstructor 活动添加到清单文件中。

    <activity
        android:name=".VirtualSkiInstructor"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    

    【讨论】:

      【解决方案2】:

      在 AndroidManifest.xml 文件中添加 VirtualSkiInstructor Activity。

      <activity android:name=".VirtualSkiInstructor"> </activity>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-08-26
        相关资源
        最近更新 更多