2013-06-12 109 views
0

嗨,那裏我看到一個教程在這裏(http://www.youtube.com/watch?v=embeFCPzRCg) 其中只有一個啓動畫面來,然後其他主屏幕來...視頻中的代碼工作正常......但是當我編碼我的自我錯誤發生在日誌貓和啓動畫面,但在進入下一個屏幕之前,應用程序崩潰。安卓初始屏幕不工作

日誌文件錯誤

塊引用

06-12 14:34:45.195: I/dalvikvm-heap(25510): Grow heap (frag case) to 13.376MB for 519700-byte allocation 

06-12 14:34:45.240: D/dalvikvm(25510): GC_CONCURRENT freed 1K, 8% free 12731K/13831K, paused 13ms+2ms, total 45ms 

06-12 14:34:45.310: D/libEGL(25510): loaded /system/lib/egl/libEGL_mali.so 

06-12 14:34:45.320: D/libEGL(25510): loaded /system/lib/egl/libGLESv1_CM_mali.so 

06-12 14:34:45.325: D/libEGL(25510): loaded /system/lib/egl/libGLESv2_mali.so 

06-12 14:34:45.325: D/(25510): Device driver API match 

06-12 14:34:45.325: D/(25510): Device driver API version: 10 

06-12 14:34:45.325: D/(25510): User space API version: 10 

06-12 14:34:45.325: D/(25510): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 
15:37:13 KST 2012 

06-12 14:34:45.365: D/OpenGLRenderer(25510): Enabling debug mode 0 

06-12 14:34:46.275: W/dalvikvm(25510): threadid=11: thread exiting with uncaught exception (group=0x411292a0) 

06-12 14:34:46.280: E/AndroidRuntime(25510): FATAL EXCEPTION: Thread-11666 

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Activity.startActivityForResult(Activity.java:3446) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Activity.startActivityForResult(Activity.java:3407) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Activity.startActivity(Activity.java:3617) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at android.app.Activity.startActivity(Activity.java:3585) 

06-12 14:34:46.280: E/AndroidRuntime(25510): at com.example.edoc_dc.Edoc_dc$1.run(Edoc_dc.java:28) 

06-12 14:34:46.320: I/Process(25510): Sending signal. PID: 25510 SIG: 9 
06-12 14:35:12.360: W/dalvikvm(25869): threadid=11: thread exiting with uncaught exception (group=0x411292a0) 

06-12 14:35:12.360: E/AndroidRuntime(25869): FATAL EXCEPTION: Thread-11681 

06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Activity.startActivityForResult(Activity.java:3446) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Activity.startActivityForResult(Activity.java:3407) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Activity.startActivity(Activity.java:3617) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at android.app.Activity.startActivity(Activity.java:3585) 

06-12 14:35:12.360: E/AndroidRuntime(25869): at com.example.edoc_dc.Edoc_dc$1.run(Edoc_dc.java:28) 

這是我的啓動畫面代碼,對於B加載第一edoc_dc.java

package com.example.edoc_dc; 

    import android.os.Bundle; 
    import android.app.Activity; 
    import android.content.Intent; 
    import android.view.Menu; 
    import android.view.MenuItem; 
    import android.support.v4.app.NavUtils; 

    public class Edoc_dc extends Activity { 

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


// meke the thread here 

    Thread splash_screen= new Thread(){ 
     public void run() { 

      try{ 
       sleep(1000); 
      }catch(Exception e){ 
       e.printStackTrace(); 
      }finally{ 
       startActivity(new Intent(getApplicationContext(), Main.class)); 
       finish(); 
      }//end finaly 

     }// end run 

    };// end thread 

    splash_screen.start(); 

}// end method 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_edoc_dc, menu); 
    return true; 
} 


} 

,這是它的activity_edoc_dc.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/ic_final" /> 

    </RelativeLayout> 

這裏是要加載的main.java package com.example.edoc_dc;

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

    public class Main extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 

    // adding the desktop to it 
    setContentView(R.layout.main_desktop); 

}// end on create 
    }// end main 

,這裏是它的XML文件main_desktop.xml

<?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:orientation="vertical" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="HERE IS THE DESKTOP" 
    android:textAppearance="?android:attr/textAppearanceSmall" /> 

    </LinearLayout> 

這裏是我的清單文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.example.edoc_dc" 
android:versionCode="1" 
android:versionName="1.0" > 

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

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".Edoc_dc" 
     android:label="@string/title_activity_edoc_dc" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

    </manifest> 

請解決該問題,並告訴該怎麼做..應用程序工作罰款剛剛崩潰之前foing到主屏幕

+1

請在此處發佈問題之前先閱讀您的日誌錯誤,並將答案寫入您的日誌。下一次的建議;)。 – grattmandu03

回答

3

您還沒有爲活動mai n在清單文件中

<activity 
    android:name=".Main" 
    android:label="@string/title_activity_edoc_dc" > 
</activity> 

在線程中使用睡眠並不是一個好設計。

如果實現ThreadHandlerThread,請確保您的UI線程不會阻塞在等待工作線程的進修do not call Thread.wait()Thread.sleep()

http://developer.android.com/training/articles/perf-anr.html

您可以使用一個處理器

private static final int SPLASH_TIME = 2 * 1000;// 3 seconds 

處理器

new Handler().postDelayed(new Runnable() { 

     public void run() { 

      Intent intent = new Intent(Edoc_dc.this,Main.class); 
      startActivity(intent); 

      Edoc_dc.this.finish(); 
     }  

    }, SPLASH_TIME); 

注:有些人認爲閃屏是邪惡的,特別是如果什麼也不做(只是延遲)。

http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/

+0

的確更加優雅!有用瞭解 – Jarvis

0
06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 

這看起來是一個問題,請檢查您的清單,有你這個聲明與活動專有名稱/包

+0

非常感謝sooo ... perfact anwer ...只是增加了活動並且工作了.. !!!謝謝你 –

0

作爲logcat的說,好像你還沒有在Manifest文件中聲明您的Activity爲「Main」。

1

你沒有聲明你的文件Main。java的到您的清單文件作爲類似錯誤的活動在這裏說:

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 
0

錯誤寫在你的logcat的所有的信:

06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 

所有活動應用程序的必須被定義AndroidManifest。您正在嘗試顯示不屬於主的活動

0

您尚未在Manifest中聲明您的主要活動,以便它拋出ActivityNotFoundException。

聲明這個 -

<activity 
     android:name=".Main"> 

</activity> 
0

答案就在你的錯誤日誌:

"06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; 
have you declared this activity in your AndroidManifest.xml?" 

你必須在你的清單文件中添加此塊:

<activity android:name="com.example.edoc_dc.Main"/> 

只是<前/ application>標籤

這是您主要活動的聲明。

0

你logcat的說,這一切:

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml? 

嘗試,宣佈在你的清單中的主要活動:

<activity android:name="com.example.edoc_dc.Main" </activity> 

另外:more info on splashscreens

另外:don't use splashscreens, it's an iOS thing :)

乾杯,希望我幫助了。