1

Splash.java

public class Splash extends Activity {

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

        final ImageView iv = (ImageView) findViewById(R.id.imageView);
        final Animation an = AnimationUtils.loadAnimation(getBaseContext(), R.anim.rotate);
        final Animation an2 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_fade_out);


        iv.startAnimation(an);
        an.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                iv.startAnimation(an2);
                finish();
                Intent i = new Intent(Splash.this, MainActivity.class);
                startActivity(i);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

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

        Button gsbtn = (Button) findViewById(R.id.gsbtn);
        Button gstbtn = (Button) findViewById(R.id.gstbtn);
        Button nhbtn = (Button) findViewById(R.id.nhbtn);
        Button settingsbtn = (Button) findViewById(R.id.settingsbtn);
        Button exitbtn = (Button) findViewById(R.id.exitbtn);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, 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();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

this is my code for main activity and splash but as soon as the emulator hits the main acticivty, the apps breaks and displays the error

"Unfortunately the app has stopped working"

The event log is not showing any bad errors but I do get this in monitor section;

02-25 22:23:17.425 2197-2197/uk.ac.hud.compugeek E/AndroidRuntime: 
FATAL EXCEPTION: main
Process: uk.ac.hud.compugeek, PID: 2197
android.content.ActivityNotFoundException: Unable to find explicit activity class {uk.ac.hud.compugeek/uk.ac.hud.compugeek.MainActivity}; have you declared this activity in your AndroidManifest.xml?
   at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1794)
   at android.app.Instrumentation.execStartActivity(Instrumentation.java:1512)
   at android.app.Activity.startActivityForResult(Activity.java:3917)
   at android.app.Activity.startActivityForResult(Activity.java:3877)
   at android.app.Activity.startActivity(Activity.java:4200)
   at android.app.Activity.startActivity(Activity.java:4168)
   at uk.ac.hud.compugeek.Splash$1.onAnimationEnd(Splash.java:41)
   at android.view.animation.AnimationSet.getTransformation(AnimationSet.java:400)
   at android.view.animation.Animation.getTransformation(Animation.java:943)
   at android.view.View.applyLegacyAnimation(View.java:15771)
   at android.view.View.draw(View.java:15887)
   at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
   at android.support.design.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1077)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
   at android.view.View.draw(View.java:16181)
   at android.view.View.updateDisplayListIfDirty(View.java:15174)
   at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
   at android.view.View.updateDisplayListIfDirty(View.java:15134)
   at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
   at android.view.View.updateDisplayListIfDirty(View.java:15134)
   at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
   at android.view.View.updateDisplayListIfDirty(View.java:15134)
   at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:281)
   at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:287)
   at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:322)
   at android.view.ViewRootImpl.draw(ViewRootImpl.java:2615)
   at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2434)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2067)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
   at android.view.Choreographer.doCallbacks(Choreographer.java:670)
   at android.view.Choreographer.doFrame(Choreographer.java:606)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5417)
   at java.lang.reflect.Method.invoke(Native Method)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-25 22:23:21.874 2197-2197/uk.ac.hud.compugeek I/Process: Sending signal. PID: 2197 SIG: 9

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="uk.ac.hud.compugeek">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" ></activity>
        <activity

            android:name=".Splash"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>
Cœur
  • 37,241
  • 25
  • 195
  • 267
EverBloom
  • 21
  • 4
  • Check your logs for the specific error. – chRyNaN Feb 25 '16 at 22:05
  • that's not helpful. it gives too many things that wouldn't make sense to me. – EverBloom Feb 25 '16 at 22:11
  • Add the logs to your question. It makes it easier for someone to help you. – chRyNaN Feb 25 '16 at 22:12
  • An Android ANR is too general but if we could see the logs we can see more specifically why the app crashed. – chRyNaN Feb 25 '16 at 22:13
  • i have added them now, so if you could have a look again plz? – EverBloom Feb 25 '16 at 22:25
  • The first line says it's unable to find the MainActivity. Go to your androidmanifest.XML file and make sure you add the Activity. – chRyNaN Feb 25 '16 at 22:38
  • This line doesn't make sense to you? `have you declared this activity in your AndroidManifest.xml?` – OneCricketeer Feb 25 '16 at 22:53
  • Words of advice, always do `File > New > Activity` instead of just making a new Java file or copying another file. The correct stuff will be added to the manifest. That is, unless you feel comfortable editing the manifest by hand. – OneCricketeer Feb 25 '16 at 22:59
  • @cricket_007 thanks and yes i have added it to the manifest xml file but still it wouldnt go there – EverBloom Feb 25 '16 at 23:00
  • @chRyNaN its there, i have edited my question too, you can have a look at the manifest xml, dont know why – EverBloom Feb 25 '16 at 23:01
  • Well, you should be getting a different error, then. – OneCricketeer Feb 25 '16 at 23:01
  • Personally, I would move `finish()` beneath `startActivity(i)`, but I don't know if that fixes anything – OneCricketeer Feb 25 '16 at 23:04
  • @cricket_007 i am not getting any error, its just in the emulator the app wpould stop at the end of the splash activity – EverBloom Feb 25 '16 at 23:11
  • If the device says "Unfortunately the app has stopped working", then there is some error happening. If you do not dismiss that dialog and you view the logs, then you should see some error. Since you added `MainActivity` to the Manifest, you should be seeing a different error than the one you included in your question. – OneCricketeer Feb 25 '16 at 23:14
  • @cricket_007 its giving me fatal exception main like this; 02-25 23:11:42.912 3027-3027/uk.ac.hud.compugeek E/AndroidRuntime: FATAL EXCEPTION: main and than with the whole thing that i have put at the top – EverBloom Feb 25 '16 at 23:17
  • Yeah, sure, Fatal Exception like before, but there is different content beneath that line. Please update your question with the new errors unless you are sure it is the same – OneCricketeer Feb 25 '16 at 23:23
  • For what it's worth, I made a brand new project, and I got it to work with your SplashActivity code to an empty MainActivity, so I imagine your problem is in the MainActivity code. – OneCricketeer Feb 25 '16 at 23:40
  • @cricket_007 i am thinking to do the same but just saying this is my third project am doing this thing with lol – EverBloom Feb 26 '16 at 00:11
  • Your code **looks** fine. We on StackOverflow would love to help, but the error in your question makes no sense now that you have added MainActivity to the Manifest. As I've been trying to tell you for the last several messages, please replace the error in your question with whatever the current problem is. I highly doubt there is no error log if the app still crashes – OneCricketeer Feb 26 '16 at 03:59

1 Answers1

2

All activities need to be added to the manifest.

<activity
    android:name=".MainActivity">
</activity>
gunterB
  • 195
  • 3
  • 6