Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:44:52+00:00 2026-06-13T00:44:52+00:00

Trying to write my first app on android. But the app crashes(FC) on the

  • 0

Trying to write my first app on android.
But the app crashes(FC) on the virtual device when clicking any of buttons.
Please take a look..
the MainActivity.java:

public class MainActivity extends Activity {
public EditText t1 = null, t2 = null;
Button b1 = null, b2 = null;
TextView tv1 = null,tv2 = null;
int a = 0, b = 0, S1 = 0, S2 = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    t1=(EditText)findViewById(R.id.editText1);
    t2=(EditText)findViewById(R.id.EditText2);
    b1=(Button)findViewById(R.id.button1);
    b2=(Button)findViewById(R.id.button2);
    tv1=(TextView)findViewById(R.id.TextView1);
    tv2=(TextView)findViewById(R.id.TextView2);


}
public void onClick1() 
{
    tv1.clearComposingText();
  a=Integer.parseInt(t1.getText().toString());
   tv1.setText(S1+=a);
   }

public void onClick2() 
{
    tv2.clearComposingText();
  b=Integer.parseInt(t2.getText().toString());
   tv2.setText(S2+=b);
   }

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

activity_main.xml:

<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" >

<Button
    android:id="@+id/button1"
    android:layout_width="80dp"
    android:layout_height="60dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="30dp"
    android:text="Add"
    android:onClick="onClick1" />

<Button
    android:id="@+id/button2"
    android:layout_width="80dp"
    android:layout_height="60dp"
    android:layout_alignBaseline="@+id/button1"
    android:layout_alignBottom="@+id/button1"
    android:layout_marginLeft="26dp"
    android:layout_toRightOf="@+id/button1"
    android:text="Add"
    android:onClick="onClick2" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="80dp"
    android:layout_height="60dp"
    android:layout_alignLeft="@+id/button1"
    android:layout_below="@+id/button1"
    android:layout_marginTop="24dp"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/EditText2"
    android:layout_width="80dp"
    android:layout_height="60dp"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignLeft="@+id/button2"
    android:ems="10" />

<TextView
    android:id="@+id/TextView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/editText1"
    android:layout_centerVertical="true"
    android:text="" />

<TextView
    android:id="@+id/TextView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/TextView1"
    android:layout_alignLeft="@+id/EditText2"
    android:text="" />

and logcat log file:

10-14 17:36:35.714: E/AndroidRuntime(697): FATAL EXCEPTION: main
10-14 17:36:35.714: E/AndroidRuntime(697): java.lang.IllegalStateException: Could not find a method onClick1(View) in the activity class com.example.blot.MainActivity for onClick handler on view class android.widget.Button with id 'button1'
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.view.View$1.onClick(View.java:2131)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.view.View.performClick(View.java:2485)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.view.View$PerformClick.run(View.java:9080)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.os.Handler.handleCallback(Handler.java:587)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.os.Looper.loop(Looper.java:123)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-14 17:36:35.714: E/AndroidRuntime(697):  at java.lang.reflect.Method.invokeNative(Native Method)
10-14 17:36:35.714: E/AndroidRuntime(697):  at java.lang.reflect.Method.invoke(Method.java:507)
10-14 17:36:35.714: E/AndroidRuntime(697):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-14 17:36:35.714: E/AndroidRuntime(697):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-14 17:36:35.714: E/AndroidRuntime(697):  at dalvik.system.NativeStart.main(Native Method)
10-14 17:36:35.714: E/AndroidRuntime(697): Caused by: java.lang.NoSuchMethodException: onClick1
10-14 17:36:35.714: E/AndroidRuntime(697):  at java.lang.ClassCache.findMethodByName(ClassCache.java:247)
10-14 17:36:35.714: E/AndroidRuntime(697):  at java.lang.Class.getMethod(Class.java:962)
10-14 17:36:35.714: E/AndroidRuntime(697):  at android.view.View$1.onClick(View.java:2124)
10-14 17:36:35.714: E/AndroidRuntime(697):  ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:44:53+00:00Added an answer on June 13, 2026 at 12:44 am

    Simply try this…..

    – First remove the onClick1() and onClick2() methods.

    – Use Anonymous Inner class for registering and implementing the method onClick() of Interface OnClickListener

    b1.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                              tv1.clearComposingText();
                              a=Integer.parseInt(t1.getText().toString());
                              tv1.setText(S1+=a);
    
    
                }
            });
    
    
    b2.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                         tv2.clearComposingText();
                             b=Integer.parseInt(t2.getText().toString());
                             tv2.setText(S2+=b);
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write my first Android app. It will take a number input
I am trying to write my first Android app, and I'm having trouble. I
I'm trying to write my first iPhone app, and I'm using a date picker
Just trying to write my first ever WP7 app. I have several hundreds of
I'm trying to write my first simple mvc app. I have a Main View
I'm trying to write my first jquery plugin but I'm running into some difficulties.
I am trying to write my very first python script. This was working but
I am trying to write an Android app to connect to an existing web
I am trying to write my first app- a simple application where the user
I'm trying to write a voip app for Android, using the Android SIP API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.