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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:20:06+00:00 2026-06-07T22:20:06+00:00

I cannot set the position of my Horizontal ScrollView in my main.xml because I

  • 0

I cannot set the position of my Horizontal ScrollView in my main.xml because I am unable to target it using the code below. This method has always worked for me when targeting TextViews or Buttons, so i’m not sure why a ScrollView should be treated differently.

ScrollView scrollview1 = (ScrollView)findViewById(R.id.scrollview1);

So far I’ve been unable to find a working example of someone doing something similar that I could implement into my code successfully to scroll my bar to where it needs to be.

Here is what my error log displays during the app crash

dalvikvm threadid=1: thread exiting with uncaught exception (group=0x409c01f8)

AndroidRuntime FATAL EXCEPTION: main

AndroidRuntime java.land.ClassCastException: android.widget.HorizontalScrollView cannot be cast to android.widget.ScrollView

AndroidRuntime at com.testButtons.TestButtonsActivity.onKeyDown(TestButtonsActivity.java)

Here is the code block that holds the troubled code.

I’m using the android return key to exit a menu and go back to main.xml with horizontal scrollview1 set 40dp from the left.

    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            if(pageNum < 4){

                setContentView(R.layout.main);

                ScrollView scrollview1 = (ScrollView)findViewById(R.id.scrollview1);
                //scrollview1.scrollTo(40,0);

            }else if(pageNum >= 4 && pageNum < 20){

                setContentView(R.layout.main2);
                pageNum=0;
            }

            return true;
        }

        return super.onKeyDown(keyCode, event);
    }

I’m pretty new to android app development and this form as well; as This is my first post pertaining to my first app store worthy app.

I appreciate the time you spent reading my question, and I know others android noobies will probably run into this same/similar problem and find this useful.

  • 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-07T22:20:07+00:00Added an answer on June 7, 2026 at 10:20 pm

    You’re casting it to a ScrollView when in fact it is a HorizontalScrollView. ScollView is not a parent class of HorizontalScrollView, thus your error is thrown. Change

    ScrollView scrollview1 = (ScrollView)findViewById(R.id.scrollview1);
    

    to

    HorizontalScrollView scrollview1 = (HorizontalScrollView)findViewById(R.id.scrollview1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code giving me the strange error message Uncaught TypeError: Cannot set
I cannot get/set a static variable inside a method. How can I do it?
i cannot set my theme's language to my language.. i've translated the needed field
I cannot set title_for_layout in the PagesController that comes by default with CakePHP 1.3.
I see there are several posts regarding Cannot set Property and I'm still struggling
I know that you cannot simply set DocumentRoot in htaccess but it's all I
I cannot get the DropDownHeight of the ComboBox set properly to display all the
I cannot figure out how to set an estimated maximum price for a collection
I cannot figure out how to set an array to one of two sets
I cannot for the life of me find where to set the delete rules

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.