飞溅不会去主要活动

时间:2016-02-25 22:00:31

标签: java android splash-screen main-activity

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);
    }
}

这是我的主要活动和启动代码,但是一旦模拟器点击主要活动,应用程序就会中断并显示错误

  

"不幸的是,该应用已停止工作"

事件日志没有显示任何错误,但我确实在监视器部分显示了这个;

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>

1 个答案:

答案 0 :(得分:2)

需要将所有活动添加到清单中。

<activity
    android:name=".MainActivity">
</activity>