View Single Post
Old December 9th, 2012, 12:55 PM   #1 (permalink)
VaMoose
New Member
Thread Author (OP)
 
Join Date: Dec 2012
Location: Bryanston, Gauteng, South Africa
Gender: Male
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 0 Times in 0 Posts
Cry Button onClick setText causes Crash ?

Hi there. I am trying to set the Text of a Text View when a button is clicked.

I have been struggling, because the variable will increment, but If i put the code in to set the text, it crashes the app ?

Here is my code when it crashes:

Quote:
package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Game extends Activity{

Button spam;
TextView timeleft, score;
public int points = 0;
public int finalscore = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.game);

spam = (Button) findViewById(R.id.gameSpamButton);
timeleft = (TextView) findViewById(R.id.gameTimeLeftTextView);
score = (TextView) findViewById(R.id.gameScoreTextView);

spam.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
points++;
score.setText(points); // this is the line that crashes the app
}
});
}
}
however if I comment out the line
Quote:
score.setText(points);
, the app doesnt crash, but it doesnt do anything then.

Please can someone help me!
VaMoose is offline  
Reply With Quote