App crashes after splash screen.Help


  1. Nitrosolid

    Nitrosolid Member

    Hello.I made a application that adds by 10's and i decided for the first time to make a splash screen.For some reason the app crashes after the Splash screen.Idk if the problem is with the manifest or the java code.I really appreciate the help.

    Starting point.Java
    PHP:
    1.  
    2. package com.example.counter;
    3.  
    4.  
    5.  
    6. import android.os.Bundle;
    7. import android.app.Activity;
    8. import android.view.Menu;
    9. import android.view.View;
    10. import android.widget.Button;
    11. import android.widget.TextView;
    12.  
    13.  
    14. public class Startingpoint extends Activity {
    15.  
    16.     int counter;
    17.     Button add, sub;
    18.     TextView display;
    19.    
    20.     @Override
    21.     protected void onCreate(Bundle savedInstanceState) {
    22.         super.onCreate(savedInstanceState);
    23.         setContentView(R.layout.main);
    24.        
    25.         counter = 0;
    26.         add = (Button) findViewById(R.id.Btnadd);
    27.         sub = (Button) findViewById(R.id.Btnsub);
    28.         display = (TextView) findViewById(R.id.Tv1);
    29.        
    30.         add.setOnClickListener(new View.OnClickListener() {
    31.            
    32.             @Override
    33.             public void onClick(View v) {
    34.                 // TODO Auto-generated method stub
    35.                 counter += 10;
    36.                 display.setText("Current number is " + counter);
    37.             }
    38.         });
    39.        
    40.         sub.setOnClickListener(new View.OnClickListener() {
    41.            
    42.             @Override
    43.             public void onClick(View v) {
    44.                 // TODO Auto-generated method stub
    45.                 counter -= 10;
    46.                 display.setText("Current number is " + counter);
    47.                
    48.             }
    49.         });
    50.        
    51.        
    52.         }
    53.    
    54.    
    55.    
    56.     @Override
    57.     public boolean onCreateOptionsMenu(Menu menu) {
    58.         // Inflate the menu; this adds items to the action bar if it is present.
    59.         getMenuInflater().inflate(R.menu.main, menu);
    60.         return true;
    61.     }
    62.  
    63. }
    64.  
    Splash.Java
    PHP:
    1.  
    2. package com.example.counter;
    3.  
    4. import android.app.Activity;
    5. import android.content.Intent;
    6. import android.os.Bundle;
    7.  
    8. public class Splash extends Activity {
    9.  
    10.     @Override
    11.     protected void onCreate(Bundle Splasher) {
    12.         // TODO Auto-generated method stub
    13.         super.onCreate(Splasher);
    14.         setContentView(R.layout.splash);
    15.        
    16.         Thread timer = new Thread(){
    17.             public void run(){
    18.                 try{
    19.                     sleep(5000);
    20.                    
    21.                 } catch (InterruptedException e){
    22.                     e.printStackTrace();
    23.                    
    24.                 }finally{
    25.                     Intent startx = new Intent("com.example.counter.STARINGPOINT");
    26.                     startActivity(startx);
    27.                 }
    28.             }
    29.         };
    30.         timer.start();
    31.        
    32.        
    33.        
    34.     }
    35.  
    36. }
    37.  
    Manifest
    PHP:
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.example.counter"
    5.     android:versionCode="1"
    6.     android:versionName="1.0" >
    7.  
    8.     <uses-sdk
    9.         android:minSdkVersion="8"
    10.         android:targetSdkVersion="17" />
    11.  
    12.     <application
    13.         android:allowBackup="true"
    14.         android:icon="@drawable/ic_launcher"
    15.         android:label="@string/app_name"
    16.         android:theme="@style/AppTheme" >
    17.         <activity
    18.             android:name=".Splash"
    19.             android:label="@string/app_name" >
    20.             <intent-filter>
    21.                 <action android:name="android.intent.action.MAIN" />
    22.  
    23.                 <category android:name="android.intent.category.LAUNCHER" />
    24.             </intent-filter>
    25.         </activity>
    26.        
    27.        
    28.         <activity
    29.             android:name=".startingPoint"
    30.             android:label="@string/app_name" >
    31.             <intent-filter>
    32.                 <action android:name="com.example.counter.STARINGPOINT" />
    33.  
    34.                 <category android:name="android.intent.category.DEFUALT" />
    35.             </intent-filter>
    36.         </activity>
    37.        
    38.     </application>
    39.  
    40. </manifest>
    41.  

    Advertisement
    :
  2. magi_apps

    magi_apps Member

    Hi, Could you post your exception stack trace. By looking at the code I can hazard a guess though. Instead of using a new thread use a Handler (which acts like a scheduler on the main UI thread). In the current code, your activity Starting Point is being invoked from a non UI thread (non main thread) which I believe could be causing the issue. If you do need to have a new thread in the splash screen use runOnUIThread to post to the UI thread.
  3. Nitrosolid

    Nitrosolid Member

    Im a begginer and i dont know what exception stack trace is.Could you tell me how i can get it.Thank you.
  4. magi_apps

    magi_apps Member

    No worries - a journey of a thousand miles still has to start with the first step. If you are using eclipse, check the logcat output for an exception stack (it will be in red). It will mention the reason why the app crashed. Logcat is one of the views that you should see towards the bottom panel in eclipse. Hope this helps. Use google for getting to use the eclipse and logcat if required.
  5. Nitrosolid

    Nitrosolid Member


    I see it and it says "com.example.counter.Splash$1.run(Splash.java:24)".Also when i double click it highlights "startActivity(startx);".
  6. DR doggy

    DR doggy Member

    hi i noticed this line in your manifest

    <action android:name="com.example.counter.STARINGPOINT" />

    if im not mistaken you maybe missing a "T" ie starTingpoint
  7. GeorgeN

    GeorgeN Well-Known Member

    Try:

    Code (Text):
    1. Intent startx = new Intent (getBaseContext(), Startingpoint.class);
    You shouldn't need the intent filter in your Startingpoint manifest entry (although it won't do any harm), but you do need to make sure the name attribute exactly matches your class name (e.g. it should be 'android:name=".Startingpoint"' and not 'android:name=".startingPoint"'.)
Loading...

Share This Page