2012-11-18 45 views
2

我不明白爲什麼當我在模擬器中運行它時,它強制關閉。我做了一個閃屏,並且出現沒有問題,但它不會通過了:我的Android應用程序保持關閉

啓動畫面後
public class MainActivity extends Activity 
{ 
protected boolean _active = true; 
protected int _splashTime = 5000; 

// Called when the activity is first created. 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    // thread for displaying the SplashScreen 
    Thread splashTread = new Thread() 
    { 
     @Override 
     public void run() 
     { 
      try 
      { 
       int waited = 0; 
       while(_active && (waited < _splashTime)) 
       { 
        sleep(100); 
        if(_active) 
        { 
         waited += 100; 
        } 
       } 
      } 
      catch(InterruptedException e) 
      { 
       // do nothing 
      } 
      finally 
      { 
       finish(); 
       startActivity(new Intent("com.example.textsmslock.EnableActivity")); 
       stop(); 
      } 
     } 
    }; 
    splashTread.start(); 
} 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN) { 
     _active = false; 
    } 
    return true; 
} 
} 

,它應該是去下面的另一個活動代碼:

public class Enable extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_enable); 
    // getActionBar().setDisplayHomeAsUpEnabled(true); 
} 
@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_enable, menu); 
    return true; 
} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
     case android.R.id.home: 
      NavUtils.navigateUpFromSameTask(this); 
      return true; 
    } 
    return super.onOptionsItemSelected(item); 
} 
public void EnableYes(View view) 
{ 
    startActivity(new Intent("com.example.textsmslock.EnterPin")); 
} 
public void EnableNo(View view) 
{ 

} 

} 

紅Logcats

11-17 21:04:53.504: E/Zygote(32): setreuid() failed. errno: 2 
11-17 21:05:00.924: E/Zygote(32): setreuid() failed. errno: 17 
11-17 21:05:02.074: E/BatteryService(58): usbOnlinePath not found 
11-17 21:05:02.074: E/BatteryService(58): batteryVoltagePath not found 
11-17 21:05:02.074: E/BatteryService(58): batteryTemperaturePath not found 
11-17 21:05:02.094: E/SurfaceFlinger(58): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake 
11-17 21:05:07.994: E/EventHub(58): could not get driver version for /dev/input/mouse0, Not a typewriter 
11-17 21:05:07.994: E/EventHub(58): could not get driver version for /dev/input/mice, Not a typewriter 
11-17 21:05:08.653: E/System(58): Failure starting core service 
11-17 21:05:08.653: E/System(58): java.lang.SecurityException 
11-17 21:05:08.653: E/System(58): at android.os.BinderProxy.transact(Native Method) 
11-17 21:05:08.653: E/System(58): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 
11-17 21:05:08.653: E/System(58): at android.os.ServiceManager.addService(ServiceManager.java:72) 
11-17 21:05:08.653: E/System(58): at com.android.server.ServerThread.run(SystemServer.java:184) 
11-17 21:05:09.293: E/SoundPool(58): error loading /system/media/audio/ui/Effect_Tick.ogg 
11-17 21:05:09.304: E/SoundPool(58): error loading /system/media/audio/ui/KeypressStandard.ogg 
11-17 21:05:09.304: E/SoundPool(58): error loading /system/media/audio/ui/KeypressSpacebar.ogg 
11-17 21:05:09.304: E/SoundPool(58): error loading /system/media/audio/ui/KeypressDelete.ogg 
11-17 21:05:09.304: E/SoundPool(58): error loading /system/media/audio/ui/KeypressReturn.ogg 
11-17 21:05:35.019: E/AndroidRuntime(272): FATAL EXCEPTION: Thread-8 
11-17 21:05:35.019: E/AndroidRuntime(272): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=this, com.example.textsmslock.Enable.class } 
11-17 21:05:35.019: E/AndroidRuntime(272): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408) 
11-17 21:05:35.019: E/AndroidRuntime(272): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 
11-17 21:05:35.019: E/AndroidRuntime(272): at android.app.Activity.startActivityForResult(Activity.java:2817) 
11-17 21:05:35.019: E/AndroidRuntime(272): at android.app.Activity.startActivity(Activity.java:2923) 
11-17 21:05:35.019: E/AndroidRuntime(272): at com.example.textsmslock.MainActivity$1.run(MainActivity.java:45) 

**end of logcat** 
+0

能否請您粘貼從logcat的堆棧跟蹤的意圖過濾看到飛機墜毀是什麼? – LuxuryMode

+0

這是你的意思? –

+0

[2012-11-17 21:04:46 - Emulator]無法獲取wglGetExtensionsStringARB [2012-11-17 21:04:46 - Emulator]無法獲取wglGetExtensionsStringARB [2012-11-17 21:04:46 - 模擬器]無法獲得wglGetExtensionsStringARB [2012-11-17 21:04:46 - 模擬器]無法獲得wglGetExtensionsStringARB [2012-11-17 21:04:46 - 模擬器]無法獲取wglGetExtensionsStringARB [2012-11 -17 21:04:46 - Emulator]無法獲取wglGetExtensionsStringARB [2012-11-17 21:04:46 - Emulator]無法獲取wglGetExtensionsStringARB [2012-11-17 21:04:46 - Emulator] could not得到wglGetExtensionsStringARB –

回答

0

我錯過了我的清單

<intent-filter> 
      <action android:name="com.example.textsmslock.Enable" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
0

沒有一個堆棧跟蹤其很難說,但最有可能的是沒有活動稱爲EnableActivity。根據您的代碼,該活動被稱爲Enable

類型安全的方式做到這一點,是不使用字符串,而是startActivity(new Intent(this, com.example.textsmslock.Enable.class))

+0

我做了你推薦的改變,我得到了力量關閉。最初,我有startActivity(新的意圖(這,com.example.textsmslock.Enable.class)) –

+0

設置爲startActivity(新的意圖(com.example.textsmslock.Enable))...你怎麼建議添加.class?我只是好奇。我是新來的應用程序編程一般 –

+0

@DaJaynaeWilliams,因爲你可以創建一個Intent的方法之一是引用一個類Object。所以如果你使用一個字符串,那裏沒有類型安全;這意味着您只會在運行時看到崩潰。而如果你使用類對象,如果沒有這樣的類,你會得到一個編譯時錯誤。請注意,如果您尚未在清單中聲明Enable活動,它仍然會在運行時崩潰。 – LuxuryMode

0

首先,我認爲你開始第二Activity錯誤。在你MainActivity,你有這樣的:

startActivity(new Intent("com.example.textsmslock.EnableActivity")); 

當你應該有這樣的事情:

startActivity(new Intent(this, Enable.class)); 

其次,這是多麼Enable可能看起來像在您的清單。你真的沒有指示與meta-data標籤父活動:

<activity android:name="com.example.textsmslock.Enable" 
    android:label="@string/title_activity_enable"></activity> 

第三,當人們說「堆棧跟蹤,」你通常看到在logcat的紅色打印出來。這意味着有一個Exception或拋出一個錯誤。

+0

好的。不幸的是,他們正在踢我離開實驗室過夜。但明天我會試試這個。非常感謝! –

相關問題