Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Error: SplashActivity is not an Activity subclass or alias

I have a library project which has all functionality and some activities, and I also have a wrapper activity which only has a JSON configuration string and some styling. I imported the library to the wrapper project, and in the wrapper project I'm setting one of the library's activities as the launch activity, but then get an error that the selected activity from the library is not an activity subclass or alias.

What does that mean and can I correct this?

The Activity that is supposed to be launched:

package dk.borgertip.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import dk.borgertip.R;

public class SplashActivity extends Activity {

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

        Thread startTimer = new Thread() {
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent i = new Intent(SplashActivity.this, MainActivity.class);
                    startActivity(i);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        startTimer.start();
    }


    @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_splash, 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);
    }
}

The project structure: (The Borgertip module is the library that contains the activity to launch which extends Activity)

The Borgertip module is the library that contains the activity to launch

The 'Edit Configuration' dialog with the error:

enter image description here

What do I do wrong?

like image 958
Ambran Avatar asked Feb 28 '15 18:02

Ambran


1 Answers

I had the same problem, in this particular case it was caused after refactoring some code and delete the activity that was set as the application main activity.

I made sure the <activity></activity> declaration was also removed from the manifest.xml file but it was still set as the main activity whitin the Run/Debug configurations section in Android Studio.

Just go to run/Edit configurations.../Android App/app

Select the "General" tab and look at the "Launch Options" section. There you can choose the activity you want to set as the main one.

Hope this will be useful for someone else.

like image 176
Sandoval0992 Avatar answered Oct 10 '22 02:10

Sandoval0992