1

I cannot display the message

I tried System.out.println(); but it doesnt work in android studio

public void submitOrder(View view) {
    String message = "Total:";
    displayMessage(message);
}

3 Answers3

2

System.out.println does work in Android Studio 3.4.1 but you can't see the output on emulator or any physical device. Result will be displayed on Logcat as I/System.out:.

com.example.printdemo I/System.out: Test Message

Pranshu K
  • 73
  • 11
1

You can use Log.d("MyApp","I am here");

from https://developer.android.com/reference/android/util/Log.html

I think you will find your answer in this question Why doesn't "System.out.println" work in Android?


You could also use an android.widget.Toast for this nice popup messages

e.g. Toast.makeText(getApplicationContext(), "ToastMessage", Toast.LENGTH_LONG).show();

take a look at https://www.mkyong.com/android/android-toast-example/

JavaMan
  • 1,142
  • 12
  • 22
0

It depends where you want to display your message i.e. if you want your message to be displayed in Logcat then logging can be really helpful. For more info about log and logging please go through https://developer.android.com/reference/android/util/Log

And if you want your message to be displayed on the emulator or any physical devices then Toasts will help you. They provide feedback about an operation in a small popup. example

And the code for this

Toast toast = Toast.makeText(getApplicationContext(), "Message", Toast.LENGTH_SHORT).show();