The constructor Intent is undefined

前端 未结 3 1868
别跟我提以往
别跟我提以往 2020-12-15 10:26

I have the content module loaded, the specific error I\'m getting is: The constructor Intent(new View.OnClickListener(){}, Class) is undefined

3条回答
  •  旧巷少年郎
    2020-12-15 11:07

    Change this:

    new Intent(this, ContactWidget.class);
    

    to

    new Intent(ContactWidget.this, ContactWidget.class);
    

    The error happens because, in that case, this is referencing the instance of OnClickListener, but the Intent's constructor expects a Context. The context you have to pass is the reference to the activity itself, thus you have to access it explicitly using ContactWidget.this.

提交回复
热议问题