Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the error "MyActivity is not an enclosing class?"

I had a libgdx program which starts with the following class:

public class MyActivity extends AndroidApplication implements IActivityRequestHandler

I needed to have an Activity class to detect screen size using Display (I can't do that in an AndroidApplication class).

So I added the following class as my launcher Activity:

public class MyActivity1 extends Activity

So in my new class MyActivity1 I try to run my old class MyActivity:

Intent myIntent = new Intent(MyActivity.this, MyActivity.class);
startActivity(myIntent);

But I got the following compilation error: MyActivity is not an enclosing class

Manifest is as follows

<activity android:name=".MyActivity1"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
<activity android:name=".MyActivity"/>

Why am I getting this error?

like image 303
nms Avatar asked Mar 15 '13 23:03

nms


1 Answers

Try with this

  Intent myIntent = new Intent(MyActivity1.this, MyActivity.class);
  startActivity(myIntent);

The new Intent requires the current activity's context (first param) and the class which you want initializate (second param).

like image 74
SolArabehety Avatar answered Nov 15 '22 04:11

SolArabehety