Android 访问变量时出错
我在访问另一个类中的一个类的对象时出错。下面是我的代码:Android 访问变量时出错,android,timer,Android,Timer,我在访问另一个类中的一个类的对象时出错。下面是我的代码: package FinalProj.com; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.os.CountDownTimer; public class iFallApp extends Activity{ public Object textView1; @Overri
package FinalProj.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.os.CountDownTimer;
public class iFallApp extends Activity{
public Object textView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//TextView textview = new TextView(this);
//textview.setText("This is the iFall tab");
// setContentView()
setContentView(R.layout.ifallapp);
View textView1 = findViewById(R.id.textView1);
MyCount counter = new MyCount(5000,1000);
counter.start();
}
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
iFallApp app1 = new iFallApp();
@Override
public void onFinish() {
// TODO Auto-generated method stub
app1.textView1.setText("done");
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
}
}
我正在尝试将类iFallApp的textView1访问到类Mycount中。然而,对于textView1,它并没有给我一个错误,但错误是类型对象的方法setTextstring未定义
请建议。更改
public Object textView1;
到
改变
View textView1 = findViewById(R.id.textView1);
到
您有一个名为textView1的实例变量,该变量定义为iFallApp类中的对象。这是在行app1.textView1.setTextdone中访问的内容
View textView1 = findViewById(R.id.textView1);
textView1=(TextView) findViewById(R.id.textView1);