2011-05-07 85 views
0

訪問另一個類中的對象時出現錯誤。以下是我的代碼:訪問變量時出錯

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 

     } 
    } 

} 

我試圖訪問myFount類的iFallApp的textView1。然而,它不給我一個textView1的錯誤,但錯誤是方法「setText(字符串)」未定義類型的對象。

請建議。

回答

0

變化

public Object textView1; 

public TextView textView1; 

和改變

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

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

喲你有一個名爲textView1的實例變量被定義爲iFallApp類中的一個對象。這就是你的行app1.textView1.setText(「完成」)正在訪問什麼