2017-08-16 95 views
-2

我正在編寫一個包含啓動畫面的新應用程序。 我已經完成了,它都很好。在我再次打開android studio來處理導航欄之後,我嘗試運行應用程序來查看結果,但應用程序在啓動屏幕顯示後停止並崩潰。我的Android應用程序在啓動畫面後停止響應

這是主類

package com.example.computer.bsinfoshop; 




public class Main extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 




    } 


} 

,這是類OD閃屏

package com.example.computer.bsinfoshop; 

import android.graphics.Typeface; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.content.Intent; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class Screen extends AppCompatActivity { 
    TextView tv; 
    ImageView img; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_screen); 

     tv = (TextView)findViewById(R.id.textView); 
     img = (ImageView)findViewById(R.id.imageView); 

     Typeface font = Typeface.createFromAsset(getAssets(),"fonts/Satisfy-Regular.ttf"); 
     tv.setTypeface(font); 

     img.setImageResource(R.drawable.rsz_2rsz_img); 



     Thread timerThread = new Thread(){ 
      public void run(){ 
       try 
       { 
        sleep(3700); 

       } 
       catch(InterruptedException e) 
       { 
        e.printStackTrace(); 
       } 
       finally { 
        Intent intent = new Intent(Screen.this , Main.class); 
        startActivity(intent); 

       } 
      } 
     }; 
     timerThread.start(); 

    } 

    @Override 
    protected void onPause() { 

     super.onPause(); 
     finish(); 
    } 

} 

,並在這些地方我認爲是問題

清單文件

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.computer.bsinfoshop"> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/logo" 
     android:label="@string/app_name"> 

     <activity 
      android:name=".Screen" 
      android:theme="@style/App"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <activity android:name=".Information" 
      android:label="Information" 
      android:theme="@style/AppTheme"> 
     </activity> 

     <activity 
      android:name="com.example.computer.bsinfoshop.Main" 
      android:theme="@style/AppTheme"> 
     </activity> 

    </application> 

</manifest> 

我只想知道我的代碼中存在什麼問題,我該如何解決這個問題。謝謝^^

+0

*「...但是在啓動畫面顯示後應用程序停止並崩潰」*發生這種情況並且您需要幫助時,您需要發佈您的堆棧跟蹤以便我們可以看到錯誤 – codeMagic

回答

-1

更改主題到這樣的事情:

new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      finish(); 
      startActivity(new Intent(Screen.this, Main.class)); 
     } 
    }, 1500); 
+0

代碼只有答案很少被認爲是高質量。你應該考慮添加*你的代碼有哪些*不同,以及*爲什麼它應該解決OP問題。 – codeMagic

-1

說實話,我覺得這是不是創建一個閃屏的正確途徑。這樣你強迫用戶等待3秒鐘,這會導致糟糕的用戶體驗。

看看該教程,你的用戶會感謝你! https://www.bignerdranch.com/blog/splash-screens-the-right-way/

+0

這不是問題的答案。它應該是一個評論。 – codeMagic

+0

對不起。我沒有足夠的信譽來寫這個問題的評論..這是問題,否則我會這樣做.. – Swittmann

相關問題