scamexdotexe
scamexdotexe

Reputation: 159

InstantiationException while extending the Abstract class on Android

I have an abstract class called Screen implemented this way....

public abstract class Screen {
    protected final Game game;

    public Screen(Game game) {
    this.game = game;
    }

    public abstract void update(float deltaTime);
    public abstract void present(float deltaTime);
    public abstract void pause();
    public abstract void resume();
    public abstract void dispose();
}

and a class extending the Screen class

public class LoadingScreen extends Screen {

    public LoadingScreen(Game game) {
        super(game);
    }


    @Override
    public void update(float deltaTime) {


    }

    @Override
    public void present(float deltaTime) {
        // TODO Auto-generated method stub

    }

    @Override
    public void pause() {
        // TODO Auto-generated method stub

    }

    @Override
    public void resume() {
        // TODO Auto-generated method stub

    }

    @Override
    public void dispose() {
        // TODO Auto-generated method stub

    }

}

But when I tried to execute the project, I got the below log:

04-07 03:01:09.603: E/AndroidRuntime(1107): FATAL EXCEPTION: main
04-07 03:01:09.603: E/AndroidRuntime(1107): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mobi.classic.snake/com.mobi.classic.snake.LoadingScreen}: java.lang.InstantiationException: com.mobi.classic.snake.LoadingScreen
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.os.Looper.loop(Looper.java:123)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at java.lang.reflect.Method.invokeNative(Native Method)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at java.lang.reflect.Method.invoke(Method.java:521)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at dalvik.system.NativeStart.main(Native Method)
04-07 03:01:09.603: E/AndroidRuntime(1107): Caused by: java.lang.InstantiationException: com.mobi.classic.snake.LoadingScreen
04-07 03:01:09.603: E/AndroidRuntime(1107):     at java.lang.Class.newInstanceImpl(Native Method)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at java.lang.Class.newInstance(Class.java:1429)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-07 03:01:09.603: E/AndroidRuntime(1107):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-07 03:01:09.603: E/AndroidRuntime(1107):     ... 11 more

I am new to Android Game Programming and I don't have any idea about what is the problem all about, I already googled the problem and looked at some similar question here but I didn't get the answer. Please do help me...

Upvotes: 0

Views: 362

Answers (2)

MAC
MAC

Reputation: 15847

you have LoginScreen as main class so you must need to

extend some Activity class.

class LoginScreen extends Activity
{
   onCreate(....)
   {
    new ABC();
   super(..);
   }

    class ABC extends Screen
    {
     // your code goes here...
    }
}

Upvotes: 1

dmon
dmon

Reputation: 30168

It seems like you're trying to use the LoadingScreen class as an Activity, but it's not. You can only use Activities (or classes that extend from Activity). Check out the hello world sample.

Upvotes: 1

Related Questions