2012-02-03 160 views
2

(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> 

(strings.xml中)

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

回答

0

添加VirtualSkiInstructor活動在AndroidManifest.xml文件。

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

檢查您的menifest文件。 – 2012-02-03 16:00:13

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> 
相關問題