I get 3 errors when I try to run timer
Syntax error on Token "Void", @ expected
run cannot be resolved to a type
Sytax error, insert enumBody to complete BlockStatement!
These are 3 errors I get at the below script. What might be problem? Notice that all unneeded stuff probably belongs to my other functions and stuff. I do have all imports too in reality :)
import android.app.Activity;
import android.content.Intent;
public class MainStuff extends Activity {
TextView tere;
TextView dateatm;
TextView timeatm;
String nimi;
String ip;
protected static final int REFRESH = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
// Refresh after 5 sec... //
Threa开发者_StackOverflow社区d refresherAplle = new Thread();
public void run(){
try{
int refresherApple = 0;
while (refresherApple < 5000){
sleep(100);
refresherApple = refresherApple + 100;
}
startActivity(new Intent("viimane.voimalus.REFRESHER"));
}
finally{
finish();
}
}
Your Thread definition is incorrect. The semi-colon at the end terminates the statement.
Do it like this instead.
Thread refreshAplle = new Thread() {
public void run() {
....
}
};
Currently you have a method inside a method. Thats the reason for all the token exceptions.
It should be new Thread() {
i.e. an opening curly brace which, when used as new Class() {
, is the syntax used to create a new anonymous inner class that extends/implements the declared Class (Thread in this case).
At the moment you just create an instance of Thread()
as you terminate the line with a ;
and therefore the public void run() { }
is declared in a code block, which is illegal. To create an anonymous class you use the following syntax:
Thread refresherAplle = new Thread() { //< notice this
public void run() {
...
}
}
Your run is in the middle of know were, try this:
Thread refreshAplle = new Thread(){
public void run(){
try{
int refresherApple = 0;
while (refresherApple < 5000){
sleep(100);
refresherApple = refresherApple + 100;
}
startActivity(new Intent("viimane.voimalus.REFRESHER"));
} finally{
finish();
}
}};
Declare your thread in brackets
Thread refresherApple = new Thread(){
public void run(){
try{
int refresherApple = 0;
while (refresherApple < 5000){
sleep(100);
refresherApple = refresherApple + 100;
}
startActivity(new Intent("viimane.voimalus.REFRESHER"));
}
finally{
finish();
}
}
};
精彩评论