2016-07-11 7 views
-1

スプラッシュアクティビティを正常に起動した後、私のアプリはStartingPointの2番目のアクティビティに移動できません。アプリは「残念ながらTheNewBostonは機能しなくなった」と言って終了する。Androidアプリケーションがスプラッシュアクティビティの後にアクティビティを起動できない

関連ファイルを添付しています。誰かがこれで私を助けることを願っています。 StartingPoint.java

package com.example.thenewboston; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

public class StartingPoint extends Activity { 
    int counter; 
    Button add,sub; 
    TextView display; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_starting_point); 
     counter=0; 
     add=(Button)findViewById(R.id.addButton); 
     sub=(Button)findViewById(R.id.subButton); 
     display=(TextView) findViewById(R.id.display); 
     add.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
      counter++; 
      display.setText("Your total is = " + counter); 
      } 
     }); 

     sub.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       counter--; 
       display.setText("Your total is = " + counter); 
      } 
     }); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.starting_point, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 
     if (id == R.id.action_settings) { 
      return true; 
     } 
     return super.onOptionsItemSelected(item); 
    } 
} 

Splash.java

package com.example.thenewboston; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 

public class Splash extends Activity{ 

    @Override 
    public void onCreate(Bundle TV) { 
     // TODO Auto-generated method stub 
     super.onCreate(TV); 
     setContentView(R.layout.splash); 
     Thread timer = new Thread(){ 
      public void run(){ 
       try{ 
        sleep(5000); 
       }catch(InterruptedException e){ 
        e.printStackTrace(); 
       }finally{ 
        Intent openStatingPoint= new Intent("com.thenewboston.StartingPoint"); 
        startActivity(openStatingPoint); 

       }  

      } 
     }; 
     timer.start(); 
    } 
} 

たManifest.xml

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

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

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name=".StartingPoint" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="com.example.thenewboston.StartingPoint" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".Splash" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 
+0

logcatを追加します。クラッシュの –

+2

@Sumeet Shahはインテントを置き換えます。openStatingPoint = new Intent( "com.thenewboston.StartingPoint");インテントi =新しいインテント( this 、StartingPoint.class); – Nisarg

答えて

1

以下のようにコードを変更してみてください。

Intent openStatingPoint= new Intent(Splash.this,StartingPoint.class); 
       startActivity(openStatingPoint); 

説明:(Activityクラスは、コンテキストのサブクラスであるためSplash.thisが使用されている)は、その最初のパラメータとして コンテキスト

ここで使用されるコンストラクタはパラメータを取り システムがインテントを配信する必要のあるアプリケーションコンポーネントのクラス(この場合、開始するアクティビティはStartingPoint.class

よりBuild an Intent

+0

これは正しい@pRaNayですが、コードをダンプする代わりに、将来の人々も答えを見ることができるようにあなたがしたことを説明してください。 – basic

+0

@basicありがとう。私は編集中で、答えは編集されました。 – pRaNaY

+0

今私は再度upvoteしたい:) – basic

-1

は例外スタックトレースのためのあなたのlogcatをチェックしてください、それは多くの理由である可能性があります。 と

+1

これはコメントでなければならないと答えとして何も追加します。 – basic

0

Threadクラスは、次のようにハンドラクラスをスレッドクラスの使用を使用してので、代わりのUIスレッドでは動作しません -

Splash.java

Handler handler = new Handler(); 
handler.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      Intent openStatingPoint= new Intent(Splash.this,StartingPoint.class); // Use Explicit Intents 
      startActivity(openStatingPoint); 
      finish(); 
     } 
    }, 5000); //time in milliseconds 
関連する問題