So I'm having trouble parsing a double...

Here's my code:

public class DoubleArray
{
    static Console c;           // The output console
    static final int total = 20;
    String[] numStr = new String [total];
    Double numDouble;

    public void getAndStoreInput ()
    {
        int count = 0;
        do
        {
            c.print ("Enter Double" + (count + 1));
            c.print (": ");

            while (true)
            {
                try
                {
                    numStr [count] = c.readLine ();
                    numDouble = Double.parseDouble (numStr [count]);
                    if ((numStr [count] = c.readLine ()) == null || count < total)
                    {
                        break;
                    }
                    count++;
                }
                catch (NumberFormatException e)
                {
                    new Message ("That's not a number. Please try again.");
                }
            }
        }
        while (count < total);

    }

Error occurs here:

numDouble = Double.parseDouble (numStr [count]);

I've been able to parse Double before but I don't know why it's erroring now?

Recommended Answers

All 3 Replies

what error message do you get? have you read it?
in about 99.99% of all cases it tells you exactly what goes wrong and where it goes wrong.

You cannot assign a "double" expression to a "java.lang.Double" variable. That's the error message.

Nevermind, I used Double instead of double.. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.