Page 1 of 2

Java Help

Posted: Tue Aug 18, 2009 3:15 pm
by hallsofvallhalla
I am trying to change the value of a TextView to the random number that is rolled. For some reason the program crashes when it hits the settext line. Is there something I am missing on outputting a variable to the settext? It does work when I use a string like "test"

Code: Select all

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
btn1=(Button)findViewById(R.id.Button01);
btn1.setOnClickListener(this);
tv01=(TextView)findViewById(R.id.tv01);

}
public void onClick(View view) {
rolld6();
}
public void rolld6() {
	Random randd6 = new Random();
	int d6roll = randd6.nextInt(6) + 1;
	tv01.setText(d6roll);  <-------messes up here
}

Code: Select all

tv01.setText("test");  <-------works

Re: Java Help

Posted: Tue Aug 18, 2009 3:36 pm
by hallsofvallhalla
yipee figured it out

Code: Select all

 tv01.setText(""+d6roll); 

Re: Java Help

Posted: Tue Aug 18, 2009 4:56 pm
by kyraneth
don't want to go OT, but could you point me to some easy beginner java tuts? Or any useful resource you have, i'm looking on learning java.

Re: Java Help

Posted: Tue Aug 18, 2009 7:22 pm
by hallsofvallhalla
hehe i am actually just googling the problems as they come. I have always found it easier just figure it out as I go. I started with a blank page and said, "well how do I create a button?", so google creating a button in java. After i got the button then I asked myself "How do I amke it clickable?" I then googled that, and so on and so....I have always learned much faster this way.


K new problem. How in the hell do you delay a animation???? Like I am drawing an image and I made a for loop to cycle through the images but at a slow enough speed to see. I have tried sleep() but it wont display the images, only the last one. I have tried timer but its all crazy...ughghghg

Re: Java Help

Posted: Tue Aug 18, 2009 8:40 pm
by kyraneth
that's a good method, i should try it out, thanks :D

Re: Java Help

Posted: Mon Aug 24, 2009 10:48 pm
by Perry
hallsofvallhalla wrote: K new problem. How in the hell do you delay a animation???? Like I am drawing an image and I made a for loop to cycle through the images but at a slow enough speed to see. I have tried sleep() but it wont display the images, only the last one. I have tried timer but its all crazy...ughghghg
i usually have trouble with this too. it haven't done much java but one method that might work is to make a variable and draw the animation by what the variable says. like this

Code: Select all

int ani_tracker;
 frame_counter++;
 if(frame_counter > 0 && frame_counter < 20) ani_tacker = 1;
if(frame_counter > 19 &&  frame_counter < 40) ani_tracker = 2;
if(ani_tracker == 1) draw(frame1);
if(ani_tracker == 2) draw(frame2;
// and so on...
this is of course pseudo code and you probably need to adjust the values but it works pretty well.

EDIT: opps i forgot to mention that you need to use a timer to regulate frame_counter so that it will add at the same speed. i learned this method from a c++ tutorial but i cant seem to find it.

Re: Java Help

Posted: Thu Aug 27, 2009 7:42 pm
by Perry
http://www.loomsoft.net/resources/alltu ... esson7.htm i found that is the tutorial i mentioned in case you haven't figured it out. it isn't a java tutorial but it explains the concept i tried to explain.

Re: Java Help

Posted: Thu Aug 27, 2009 7:57 pm
by hallsofvallhalla
kewl thanks!

Re: Java Help

Posted: Thu Aug 27, 2009 8:00 pm
by Perry
for me at first it seemed overly drawn out which i think it is for simplicity but you could always make up some kind of function once you get the concept. hope it helps!

Re: Java Help

Posted: Thu Sep 03, 2009 9:11 pm
by Falken
kyraneth wrote:don't want to go OT, but could you point me to some easy beginner java tuts? Or any useful resource you have, i'm looking on learning java.
Check out: http://java.sun.com/docs/books/tutorial/
Under "Trails Covering the Basics"
Some quite ok tutorials to get started with JAVA.