Tuesday 15 February 2011

android - Toast.maketext error -


The red line below the code Toast.LENGHT_LONG

The package appeared after typing com.example.neomn Gives Myapplication1;

Import android.content.Context; Importroid.os.Bundle; Import android.support.v7.app.ActionBarActivity; Import android.view.Menu; Import android.view.MenuItem; Import android.view.View; Import android.widget.Button; Import android.widget.Toast;

Public class main activity extends actionbarter activity {

  start button = (button) ViewById (R.id.btnstartservice); Button stop = (button) Find VVBIID (RID. BTNestops); @ Override Protected Zero (Bundle Saved Instantstate) {Super. NET (Saved Instantstate); SetContentView (R.layout.activity_main); Click Start.setOnClickListener (New View.OnClickListener () {@Override Public Zero (see V) {Toast. Make Text (this, "My first service was started", Toast.LnnGH_LOG) .show ();}} );  

Because, toast. The first argument is necessary Application context and in your code, there is no reference to activity in the onclick lecturer class of the this button.

It

  Toast Make Text (main activity., "My first service started", toast.LnnHH_LOG). Show ();  

No comments:

Post a Comment