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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:05:01+00:00 2026-05-24T06:05:01+00:00

I’m sorry if this comes through as a noob question, but I’m really stuck

  • 0

I’m sorry if this comes through as a “noob” question, but I’m really stuck and I couldn’t find any help, no matter where I looked.

The problem I’m having is this:

The user fills out a textbox saying how many numbers (doubles) he is going to input next (say n)

I store that number inside the OnClickListener method (that works ok)

 

public double n;
//CODE

n = Integer.parseInt(input.getText().toString());

I then need to store the n numbers that the user will input

He will fill out the textbox, press enter and the number should be stored in an array

Something like:

int i = n;
double x[] = new double[n];

button1.onClick(View view){
   x[i] = Double.parseDouble(input.getText().toString());
   i--;
}

No matter how I declare the x[i] I get an error message. I’ve done some debugging and the error pops up whenever storring in the array occurs. I know I’m missed out something basic about this and I feel pretty dumb for getting stuck with this, but I’d really appreciate any help or suggestion you guys might have.

Thanks a lot, Eugene

P.S. I have to declare the array AFTER “n” has been inputted, however when I try to use it in the next OnClickListener, it can’t access it unless it’s declared final, or as a class variable (public/private etc.)

  • 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-24T06:05:02+00:00Added an answer on May 24, 2026 at 6:05 am
    double x[] = new double[n];
    

    should be double[] x = new double[n];

    Example:

    public static void main(String[] args) {
            int n = 10;
            double[] x = new double[n];
            x[5] = 7;
            x[1] = 31;
            for(double i: x) {
                System.out.println(i);
            }
        }
    

    Edit:
    You need to call i--; before x[i] = Double.parseDouble(input.getText().toString()); if you call new double[10] then only x[0] through x[9] are valid pointers.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.