I am creating an application called Ping in Android Studio. So far, my actions are ProfileActivity ProfileActivity and Timeline. My problem is that the button in the layout corresponding to the timeline activity has an onClick method that does not work. When the button is pressed, the emulator displays "Unfortunatley, Ping has stopped." I define onClick buttons and methods in the same way as for other buttons whose functions work, only this one does not seem to work. I get a message stating that the method was not found, but I wrote the method in the corresponding action. Here is logcat:
04-30 10:40:08.727 2075-2075/com.ping_social.www.ping E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.ping_social.www.ping, PID: 2075 java.lang.IllegalStateException: Could not find a method onProfilePress(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.widget.Button with id 'profileButton' at android.view.View$1.onClick(View.java:4007) at android.view.View.performClick(View.java:4780) at android.view.View$PerformClick.run(View.java:19866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NoSuchMethodException: onProfilePress [class android.view.View] at java.lang.Class.getMethod(Class.java:664) at java.lang.Class.getMethod(Class.java:643) at android.view.View$1.onClick(View.java:4000) at android.view.View.performClick(View.java:4780) at android.view.View$PerformClick.run(View.java:19866) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Here is my Timeline activity class:
package com.ping_social.www.ping; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; public class TimeLine extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_time_line); Log.i("LoginActivity", "Layout has been set"); } @Override public boolean onCreateOptionsMenu(Menu menu) {
And here is my timeline XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" android:theme="@style/GeneralTheme" tools:context="com.ping_social.www.ping.TimeLine"> <TextView android:text="@string/no_pings" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="30sp" android:layout_centerVertical="true" android:layout_centerHorizontal="true" android:textIsSelectable="false" android:textColor="@color/PING_TOP_BAR_RED" android:id="@+id/textView4" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="60dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/timeline_button" android:id="@+id/timelineButton" android:textColor="@color/PING_TOP_BAR_RED" android:layout_weight="1"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/new_ping_button" android:id="@+id/newPingButton" android:layout_weight="1"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/activity_button" android:id="@+id/activityButton" android:layout_weight="1"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/profile_button" android:id="@+id/profileButton" android:layout_weight="1" android:onClick="onProfilePress"/> </LinearLayout> </RelativeLayout>
I am pretty sure that there are no problems with spelling, and there are no other buttons that have the same identifier or methods that have the same name. Stuck on this for several days, any help is much appreciated!
source share