-1

If I have method in second Activity class I have crash:

09-20 13:10:03.130    8552-8552/tk.mikigal.religia E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: tk.mikigal.religia, PID: 8552
java.lang.IllegalStateException: Could not find a method testxd(View) in the activity class tk.mikigal.hds.MainActivity for onClick handler on view class android.support.v7.widget.AppCompatButton with id 'button3'
        at android.view.View$1.onClick(View.java:3956)
        at android.view.View.performClick(View.java:4640)
        at android.view.View$PerformClick.run(View.java:19421)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5476)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NoSuchMethodException: testxd [class android.view.View] ...

Code of other activity class: http://pastebin.com/jhELWSc7 I put code on pastebin beacouse its too long to paste it here. I use XML android:onClick

mikigal
  • 51
  • 1
  • 1
  • 3

1 Answers1

0

Correction:

On the emulator and most devices System.out.println gets redirected to LogCat and printed using Log.i(). This may not be true on very old or custom Android versions.

Original:

There is no console to send the messages to so the System.out.println messages get lost. In the same way this happens when you run a "traditional" Java application with javaw.

Instead, you can use the Android Log class:

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

You can then view the log either in the Logcat view in Android Studio.

The first Entry to every logging call is the log tag which identifies the source of the log message. This is helpful as you can filter the output of the log to show just your messages. To make sure that you're consistent with your log tag it's probably best to define it once as a static final String somewhere.

Log.d(MyActivity.LOG_TAG,"Application started");

There are five one-letter methods in Log corresponding to the following levels:

  • e() - Error
  • w() - Warning
  • i() - Information
  • d() - Debug
  • v() - Verbose

The documentation says the following about the levels:

Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

João Silva
  • 114
  • 9