Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Exception in thread "main" error. Can't find source?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JavaRanch! I'm trying to write a code that will take a group of numbers all on the same line and average the numbers. However, when I run my code I'm receiving the following error:

I don't know exactly what this means or how to fix it. Can anyone help?

Full code:


Sample input:
9 10 5 20
11 22 33 44 55 66 77
0
Desired output:
"[line of numbers inputted] Average = [final average]"

Thank you!
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried initializing your variables in the constructors instead of the method itself?
 
Greenhorn
Posts: 2
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarifiy: Do you mean that you want to get the total average of all of the numbers or the average of each number?
 
Bartender
Posts: 7287
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When you try to create chopper on line 26, "line" has not been initialized yet, and so is null.
 
Carey Brown
Bartender
Posts: 7287
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's so many things wrong here I don't know where to start. I would suggest starting over, write 3-5 lines of code, test it, and only when you're satisfied that they work, go on to doing another 3-5 lines of code, test that, and repeat. Concentrate on your Main class first before even starting on your Average class. You should start off with something like this. And then TEST it thoroughly.
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic