I am trying to make a simple android game, yet I am unable to switch activities. I am getting an error on my Intent() code that says:
The constructor Intent(MenuView, Class< Game >) is undefined
1 quick fix available:
Remove arguments to match Intent()
I have tried multiple solutions, and taken a lot of time, but so far no fix.
Solutions tried:
-Android Remove arguments to match "intent()"
-Android: Intent asks remove argument & getBaseContext() ask to create its method
-StartActivity() red highlighted
-error to startActivity(intent), whats going wrong?
package com.gregsapps.fallingbird;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.view.View;
public class MenuView extends View{
private Context context;
Paint text;
Paint red;
Paint pink;
Rect playRect;
boolean usePink = false;
Rect tempPlayRect;
//String playText = "PLAY";
char[] playTextArray;
int runs = 10;
public MenuView(Context context) {
super(context);
this.context = context;
this.setDrawingCacheEnabled(true);
tempPlayRect = new Rect();
playRect = new Rect();
playTextArray = new char[4];
playTextArray[0] = 'P';
playTextArray[1] = 'L';
playTextArray[2] = 'A';
playTextArray[3] = 'Y';
text = new Paint();
text.setColor(Color.BLACK);
text.setTextSize(100f);
red = new Paint();
red.setColor(Color.rgb(255, 0, 0));
red.setTextSize(100f);
pink = new Paint();
pink.setColor(Color.rgb(255, 69, 0));
System.out.println("setup");
}
protected void onDraw(Canvas canvas){
if(runs == 10) runOnce(canvas);
System.out.println("Looping");
playRect.offsetTo(canvas.getWidth()/2 - playRect.width()/2, canvas.getHeight()/3);
//System.out.println(playRect.centerX());
canvas.drawColor(Color.rgb(10, 255, 255));
canvas.drawText("FallingBird", canvas.getWidth()/2, canvas.getHeight()/10, text);
if(usePink) canvas.drawRect(playRect, pink);
else canvas.drawRect(playRect, red);
//canvas.drawText("PLAY", canvas.getWidth()/2-(playRect.width()-20)/2, canvas.getHeight()/5, text);
canvas.drawText("PLAY", canvas.getWidth()/2, (int) (canvas.getHeight()/3 + (tempPlayRect.height()+canvas.getHeight()/20)), text);
System.out.println(text.measureText("PLAY"));
runs++;
usePink = false;
//if(StaticVarHandler.touch == false){
// StaticVarHandler.touchX = -1;
// StaticVarHandler.touchY = -1;
// System.out.println("not touched!");
//}
System.out.println(StaticVarHandler.touch);
if(playRect.contains(StaticVarHandler.touchX, StaticVarHandler.touchY)){
//usePink = true;
context.startActivity(new Intent(this, Game.class));
//startActivity(i);
}
invalidate();
}
private void runOnce(Canvas canvas) {
text.setTextAlign(Align.CENTER);
text.setTextSize(canvas.getWidth()/15);
System.out.println("run once" + text.measureText("PLAY"));
text.getTextBounds(playTextArray, 0, playTextArray.length, tempPlayRect);
playRect.set(0, 0, (int) (text.measureText("PLAY")+canvas.getWidth()/20), tempPlayRect.height()+canvas.getWidth()/20);
//playRect.top += 10;
//playRect.bottom += 10;
//playRect.left += 10;
//playRect.right += 10;
runs = 0;
}
}
Error location:
System.out.println(StaticVarHandler.touch);
if(playRect.contains(StaticVarHandler.touchX, StaticVarHandler.touchY)){
//usePink = true;
context.startActivity(new Intent(this, Game.class));
//startActivity(i);
}
Manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Menu"
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=".Game"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Thanks in Advance