• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on basic java code  RSS feed

 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Help on basic java code

Hi guys. I need some help on this code. It compiles and I can get results when I run it on Netbeans but I always get RuntimeException.
I found out on Javadocs this is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine. How can I get rid of it? Any thoughts? Thanks!

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

You need to fix the problem that causes the exception. Without knowing the details, there isn't much we can advise, so start by posting the full stack trace of the exception. Also tell us in which line of code it occurs.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again
Don't use that javadocs link: use this (for Java7). What happens when you try to run that code from the command line/terminal? Do you get a compile‑time error? Have a look at this FAQ.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variable names should begin with a lower case character.
 
Peter Hoppe
Greenhorn
Posts: 4
Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nick!

Before we can help very much, could you kindly post the entire class here (Have Netbeans format it first, Source -> Format)? We'd also need you to include the full stack trace of your exception.
Don't be taken aback when you will get some comments re correct style... e.g. Carey mentioned that variable names should begin with a lower case character.

Thank you so much!

P
 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply guys. I think there's nothing wrong with the entire class. I guess it's on the code. Maybe in number formats? It run and compiles. I get results but then. I always get RuntimeExceptionHandler. I don't want my grade to be lowered because of this.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused - what does a class that's apparently part of some Facebook API have to do with this code? As I said, without seeing the full stack trace of the exception, and knowing in which line of code it occurs, there isn't much we can do to help.
 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone told me that I should replace the 'float' with 'double' (in line 14) to get rid of the RuntimeException error?

// i--
float Etminus, TrueEminus, TrueVminus, fminus1=0;


Tried it but still couldn't get rid of it. Any other thoughts guys? Thanks!
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you post the full stack trace, including the full exception text, then someone might be able to answer that question.
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using floats? Avoid floats like the plague; use doubles.
Where does π⁴ ÷ 90 come from?
 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here boss:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: possible lossy conversion from double to float
at infiniteseries.main
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't even try to run something with compile‑time errors. Sort the error out first. I suggest you remove the keyword float throughout and replace it with double. you should use doubles for just about all floating‑point arithmetic.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you're trying to run code that doesn't yet compile.

So you don't have a RuntimeException, at least not from your application, but from the IDE. And the solution to that is not to run something that doesn't yet compile.

ETA: Or put another way, what Campbell said...
 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I already replaced all float with double but still get RuntimeException error. Anyways, it compiles though, I just print-screened the results shown in the message dialog box when I ran it for my "results" section for my project (didn't show the error). Hope my prof would buy it. Thanks for the feedback guys!
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what have you got now?
 
Nick Schwartz
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally got rid of RuntimeException error guys! Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!