Tom Dunwoody
Tom Dunwoody

Reputation: 9

No suitable method for makeText() - Toast (Android)

I have defined a simple Toast that is going to display "log added" when a file has been written to. The rest of the code is just the rest of the method that writes EditText content to a file called log.txt.

I have used getActivityContext(), this and MainActivity as the context arguments in an attempt to get this to work. However for some reason it still doesn't. I have imported the correct classes, I have checked the manifest, but MainActivity is correctly declared. I have searched for the answer to this for quite sometime as I knew it would be regarded as a novice issue. But never the less, it would be nice to get an answer :)

//SEND ARRIVAL TIME
public void sendArrTime(View view) {

    btnArr = (Button) findViewById(R.id.btnArr);
    btnArr.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            //Opens log.txt
            OutputStreamWriter out = new OutputStreamWriter(openFileOutput("arrlog.txt", MODE_APPEND));

            //Writes contents to file
            etArr = (EditText) findViewById(R.id.etArr);
            String text = etArr.getText().toString();
            out.write(text);
            out.write('\n');

            //close file
            out.close();

            //Confirmation Toast
            Toast toast = Toast.makeText(this, "Log added", 3).show();


            }
        }
    );

Upvotes: 1

Views: 579

Answers (3)

Emzor
Emzor

Reputation: 1368

Use the proper context MainActivity.this NOT this.

Toast.makeText(MainActivity.this, "Log added", Toast.LENGTH_SHORT).show();

Upvotes: 0

Kiplening
Kiplening

Reputation: 1

Toast.makeText(this,"Log added"+password,Toast.LENGTH_SHORT).show();

Upvotes: 0

archived
archived

Reputation: 647

From the docs:

duration int: How long to display the message. Either LENGTH_SHORT or LENGTH_LONG

So, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG. Not '3'

Upvotes: 2

Related Questions