开发者

Creating a new Intent results in a error

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?


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.


"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"/>


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.


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


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));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜