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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:57:00+00:00 2026-05-27T08:57:00+00:00

So, I’m writing a program for Android. Right now, I’m in a class called

  • 0

So, I’m writing a program for Android. Right now, I’m in a class called GraphicsView, which extends View and implements View.OnClickListener. I have created a button mLeft, that is supposed to move an object to the left when pressed. I am trying to get this to display on the bottom left of the screen. In my constructor for GraphicsView I have the code:

mLeft = new Button (context.getApplicationContext ());
mLeft.setId (1); // wasn't sure what else to set for an id, I only did that to see if it would fix anything
mLeft.setOnClickListener (this);

And in my onDraw I have:

mLeft.draw (canvas);

With just this code, the program runs fine, and when I go to the activity that uses GraphicsView it works totally fine, except for the face that the button doesn’t show up anywhere.

I also have this doe in my constructor, right below the setOnClickListener:

mLeft.setX (0);
mLeft.setY (mDisplay.getHeight () - 64);
mLeft.setHeight (64);
mLeft.setWidth (64);
mLeft.setBackgroundColor (80000000);
mLeft.setText ("<");

Whenever I have this code in there, and I go to that activity, the program crashes. I do have onClick in there, and other than “Button mLeft” at the top, this is all of the code I have associated with this button. Basically, it looks like the program is crashing whenever I try to call any of those methods from Button. I have tried commenting these out to there there is only one of them present in the code at a time, so I know that each of them individually could kill the program.

The LogCat says: “12-04 15:11:03.581: I/dalvikvm(2692): Could not find method android.widget.Button.setX, referenced from method edu.pacificu.cs.Views.GraphicsView.”

Thank you for your help.

  • 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-05-27T08:57:01+00:00Added an answer on May 27, 2026 at 8:57 am

    mLeft = new Button (context.getApplicationContext ());

    Don’t do that. Use new Button(context), and then only if context is an Activity. Never use getApplicationContext() unless you know exactly why you are using it.

    The LogCat says: “12-04 15:11:03.581: I/dalvikvm(2692): Could not find method android.widget.Button.setX, referenced from method edu.pacificu.cs.Views.GraphicsView.”

    As @Selvin points out, you appear to be running this application on Android 2.x, using a method (setX()) that does not exist on Android 2.x. setX() and setY() are mostly for animation effects (e.g., slides). The X/Y/Z position of your View is determined by its container (layout) and that container’s configuration.

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

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a French site that I want to parse, but am running into

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.