开发者

passing reference of class to another class android error

I recently asked the precursor to this question and had a great reply. However, when i was working this into my android application i am getting an unexpected error开发者_运维问答 and was wondering if everyone could take a look at my code and help me see what i am doing wrong.

Link to the initial question: passing reference of class to another class

My ERROR: "The constructor ConnectDevice(new View.OnClickListener(){}) is undefined"

The above is an error detected by eclipse.

Thanks in advance!

Below are My code snippets:

public class SmartApp extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.intro);

        final Button connectDeviceButton = (Button) findViewById(R.id.connectDeviceButton);
        connectDeviceButton.setOnClickListener(
        new View.OnClickListener()
        { 
   @Override
   public void onClick(View v) {
    Thread cThread = new Thread(new ConnectDevice(this));
    cThread.start();
   }
  });
    }
}

public class ConnectDevice implements Runnable {

 private boolean connected;
 private SmartApp smartAppRef;
 private ObjectInputStream ois;

 public ConnectDevice(SmartApp smartAppRef) {
  this.smartAppRef = smartAppRef;
 }
}


That's because you are passing an OnClickListener object, but the constructor of the ConnectDevice class expects a SmartApp object. Why? you are doing this:

new ConnectDevice(this);

In that case, this references the OnClickListener. Change it to:

new ConnectDevice(SmartApp.this);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜