The constructor Intent is undefined

前端 未结 3 1856
别跟我提以往
别跟我提以往 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.

    0 讨论(0)
  • 2020-12-15 11:28

    The context passed in could be from a remote application host... apparently you need the app context from your app, the one with your class (your broadcast reciever for instance). Intent intent = new Intent(context.getApplicationContext(), WidgetryBroadcastReceiver.class); instead of Intent intent = new Intent(context, WidgetryBroadcastReceiver.class); go figure.

    0 讨论(0)
  • 2020-12-15 11:29

    yeah that workerd for me aswell for the error in

    Geocoder gc = new Geocoder(this, Locale.getDefault());
    
    0 讨论(0)
提交回复
热议问题