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 8371627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:12:32+00:00 2026-06-09T14:12:32+00:00

Okay, this happened when I created a simple ImageButton. I don’t see what I’m

  • 0

Okay, this happened when I created a simple ImageButton. I don’t see what I’m doing wrong though… Here’s my code:

(My Activity.Xml File):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/tapbgh"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="center"
        android:text="@string/level01"
        android:textColor="#FFFFFF" />
    <TextView
        android:id="@+id/Score"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="center"
        android:text="@string/click0"
        android:textColor="#FFFFFF"
        android:textSize="16pt" />
    <Chronometer
        android:id="@+id/Timer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="center_horizontal"
        android:text="01:00"
        android:textColor="#FFFFFF" />

    <Button
        android:id="@+id/Tap"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.81"
        android:background="@drawable/buttonbg" />
    <Button
        android:id="@+id/Menu"
        android:layout_width="270dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Menu" />

    <ImageButton
        android:id="@+id/Reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/resetbtn"
        android:src="@drawable/resetbtn" />
</LinearLayout>

(My .Java File):

package my.first.app;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.Button;
//Click Events Below This Line
public class Tap_Game_Activity extends Activity {
    private Button tapBtn;
    private Button rstBtn;
    int scr = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button Menu = (Button) findViewById(R.id.Menu);
        registerForContextMenu(Menu);
        tapBtn = (Button) findViewById(R.id.Tap);
        rstBtn = (Button) findViewById(R.id.Reset);
        rstBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                TextView Score = (TextView) findViewById(R.id.Score);
                Score.setText("0");
                scr = 0;
            }
        });
        tapBtn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                scr = scr + 1;
                TextView Score = (TextView) findViewById(R.id.Score);
                Score.setText(String.valueOf(scr));
            }
        });
    }

// Options Menu

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

    @Override
    public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, view, menuInfo);

        menu.setHeaderTitle("Menu");
        menu.add(0, view.getId(), 0, "Resume");
        menu.add(0, view.getId(), 0, "Quit");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        if(item.getTitle()=="Invoke Context Function 1") {
            contextFunction1(item.getItemId());
        }
        else if(item.getTitle()=="Invoke Context Function 2") {
            contextFunction2(item.getItemId());
        }
        else {
            return false;
        }
        return true;
    }

    public void contextFunction1(int id){
        Toast.makeText(this, "function 1 invoked!", Toast.LENGTH_SHORT).show();
    }

    public void contextFunction2(int id){

            new AlertDialog.Builder(this)
                   .setMessage("Are you sure you want to exit?")
                   .setCancelable(false)
                   .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
                            Tap_Game_Activity.this.finish();
                       }
                   })
                   .setNegativeButton("No", null)
                   .show();
        }

 }

I feel like it may be in this line:

rstBtn = (Button) findViewById(R.id.Reset);

But I still don’t understand, any help would be great, thank you.

  • 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-09T14:12:34+00:00Added an answer on June 9, 2026 at 2:12 pm

    API tells me, that we can’t cast ImageButton to Button. Try to declare rstBtn as an ImageButton and adjust the cast.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this is killing me, I can't figure out what I'm doing wrong I
Okay this question is very simple: I have a facebook page, and a website.
Okay this is definitely a n00b question but here goes. The way I understand
Okay this may be a simple question but I have yet to come with
Unsure if this should be on here or serverfault so apologies if I'm wrong.
Okay this might sound simple but there's a catch. I'll try and explain the
Okay this is a homework question, and I just don't have a clue how
Okay this is similar to my last question but what I ended up doing
Okay this may seem too simple of a question but I've wasted enough time
Okay this is my first post here so please forgive me if i mess

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.