访问变量时出错

时间:2011-05-07 21:37:09

标签: 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;

    @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错误,但错误是方法“setText(string)”未定义类型对象。

请建议。

2 个答案:

答案 0 :(得分:0)

变化

 public Object textView1; 

public TextView textView1;

并更改

View textView1 = findViewById(R.id.textView1);

textView1=(TextView) findViewById(R.id.textView1);

答案 1 :(得分:0)

您有一个名为textView1的实例变量被定义为iFallApp类中的对象。这是你的行app1.textView1.setText(“done”)

中访问的内容
相关问题