Wrong code error in setType " non-static method setType(String) "

Asked

Viewed 23 times

-2

android.support.design.widget.FloatingActionButton
    android:id="@+id/floatingActionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:onClick="Invite"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="118dp"
    android:clickable="true"
    ads:fabSize="mini"
    ads:srcCompat="@color/colorAccent" 


    public void Invite(View view) {
        Intent intent=new Intent(Intent.ACTION_SEND);
        Intent.setType("text/plain");
        Intent.putExtra(Intent.EXTRA_TEXT, "COMPARTILHAR MEU APP");
        startActivity(intent);

    }

Error:(199, 15) error: non-static method putExtra(String,String) cannot be referenced from a Static context

Error:(198, 15) error: non-static method setType(String) cannot be referenced from a Static context

1 answer

1


Your problem is here:

Intent.setType("text/plain");
Intent.putExtra(Intent.EXTRA_TEXT, "COMPARTILHAR MEU APP");

When using Intent (the class name) and not intent (the name of the variable you created), you are trying to statically access nonstatic methods, hence the error.

Your code should look like this:

intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "COMPARTILHAR MEU APP");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.