• 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
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: 1
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?
 
Saloon Keeper
Posts: 5472
55
Eclipse IDE Firefox Browser Java MySQL Database VI Editor 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
Saloon Keeper
Posts: 5472
55
Eclipse IDE Firefox Browser Java MySQL Database VI Editor 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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!