Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java array

  1. #1
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Java array

    Could someone help me figure out why is this giving me a "null error" @ speed[counter] = speedV[counter] ; Thanks

        private double [][] proDistance;
        private double[] speed;
        private double [] speedV;
        private int [] angle;
     
        Catapult(double[] speedCat , int []angleCat)
        {
        speedV= speedCat;
        angle = angleCat;
        proDistance  = new double [speedCat.length][angleCat.length];
        }
     
        public void mphToMps()
        {
            for(int counter = 0 ; counter <  speedV.length;counter++)
            {
                speed[counter] = speedV[counter] ;
            }
        }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Java array

    Check to see what variable is null on that line. Once you've done this and then looked in your code to see where you've initialized that variable, the problem and solution will become obvious.

  3. #3
    Member
    Join Date
    Dec 2012
    Posts
    127
    My Mood
    Angelic
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: Java array

    Thanks you! Didn't realize I need to set the array size, thought the sped array will just take whatever say the speedV array is.

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Java array

    Quote Originally Posted by maple1100 View Post
    Thanks you! Didn't realize I need to set the array size, thought the sped array will just take whatever say the speedV array is.
    Yep, only if you tell it to do so:

    Catapult(double[] speedCat , int []angleCat)
    {
        speedV= speedCat;
        speed = new double[speedCat.length];
        // .... etc...

  5. The Following User Says Thank You to curmudgeon For This Useful Post:

    maple1100 (February 7th, 2013)

Similar Threads

  1. Replies: 2
    Last Post: January 14th, 2013, 03:22 PM
  2. Help with java array prgm
    By sdots1 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 26th, 2012, 03:47 PM
  3. java array
    By fazmy3fvz in forum Java Theory & Questions
    Replies: 10
    Last Post: June 9th, 2012, 01:25 PM
  4. Replies: 4
    Last Post: November 14th, 2011, 10:00 PM
  5. Java Array
    By lary in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 12th, 2011, 09:29 AM