views:

74

answers:

5

when i do the fallowing i get screamed on :

Button newGameButton = (Button) this.findViewById(R.id.newGameButton);
    newGameButton.setOnClickListener(new OnClickListener() {

        public  void onClick(View view) {
            startActivity(new Intent(this,gameScreen.class));
        }
    });

apparently my this is not the one needed how can i fix this err?

+2  A: 

"get screamed on" is not that descriptive, so all anyone can do is guess at what your problem is. My guess is that you need to add the gameScreen class to the manifest file. Also, does the gameScreen class extend Activity.

<activity android:name =".gameScreen" android:label="Name Of The Activity"/>
jeremynealbrown
yes the above is written the mistake i get is :Description Resource Path Location TypeType mismatch: cannot convert from View to Button countryCityGameMenu.java ‪/countryCityGame/src/com/countryCityGame‬ line 20 Java Problemnote : i am not using android:label="Name Of The Activity"does it meter?
yoavstr
It appears that the problem is in the countryCityGameMenu class and that you are trying to cast a some View class as a Button. Without seeing the code it is difficult to diagnose.
jeremynealbrown
+1  A: 

Are you sure you've named your class gameScreen and not GameScreen? The first letter in class names should be capital.

softarn
+1  A: 

I think you need to get the context from the view (I dont have any Android developement environment at the moment)

public void onClick(View view) {
    startActivity(new Intent(view.getContext(),gameScreen.class));
}
ccheneson
+4  A: 

I think the problem is a scoping issue with your this in your onClick activity. In that instance this is referring to the onClick method not your Activity. Try changing it to this:

startActivity(new Intent(countryCityGameMenu.this,GameScreen.class));

That should adjust your scoping issue.

sgarman
this is the correct answer, even this is not referring to the method but the object
Roflcoptr
!nice one sgarman!
jeremynealbrown
first of all thank you sgarman you made my life beeter i was 2 hrs of showing my program to one of my lectures just for a review so thank u so much !!!it worked but what if i want to send arguments to another xml page ?in example i want to send to the game screen his diffcult level ?or i want in case of pause to return to earlier game which i stored ' so how do i send data ?
yoavstr
+1  A: 

did you register your activity in the manifest.xml file?

if yes you could try to do

startActivity(new Intent(countryCityGameMenu.this,GameScreen.class));

because if you use this in the OnClickListener it doesn't refer to a countryCityGameMenu instance.

hara