Error in wrong code in setType "non-static method setType (String)"

-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)   can not be referenced from a static context

     

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

    
asked by anonymous 11.06.2018 / 15:27

1 answer

1

Your problem is here:

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

By using ntent (the class name) and not i ntent (the variable name you created), you are trying to statically access non-static methods, hence the error.

Your code should look like this:

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