Long Cannot Be Dereferenced Error Java
Contents |
Reply 7 Replies - 13147 Views - Last Post: 08 December 2009 - 05:14 AM Rate Topic: #1 deCalle New D.I.C Head Reputation: 0 Posts: 4 Joined: 04-December 09 long cannot be deferenced error Posted 04 December 2009 - 09:58 PM Hey guys! double cannot be dereferenced java Here i got an extract of my homework and on this part i always get an
Double Cannot Be Dereferenced Compareto
error, whether i use toString() and parse it to int or i do it as it stands here: public void fahren(int km) { if
Double Cannot Be Dereferenced Tostring
(km < 0) { System.out.println("RUECKWAERTSGANG!!!"); km = -km; } if (kmVerbrauch * km > kraftstoffVorrat) { km = Math.round(kraftstoffVorrat / kmVerbrauch).intValue(); // HERE IS THE PROBLEM System.out.println("Zu wenig Sprit!\nAuto kann nur " + km + " Kilometer weit fahren.");
Double Cannot Be Dereferenced Intvalue
} kmStand += km; kraftstoffVorrat -= km * kmVerbrauch; } I always get the 'cannot be dereferenced' error, it's freaking me off, why the hell has someone scripted this f***ing method when it doesn't work? i just want a double to be converted into int, or a long converted into int, is it that difficult!? Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: long cannot be deferenced error #2 pbl There long cannot be dereferenced compareto is nothing you can't do with a JTable Reputation: 8374 Posts: 31,956 Joined: 06-March 08 Re: long cannot be deferenced error Posted 04 December 2009 - 10:03 PM deCalle, on 4 Dec, 2009 - 08:58 PM, said:Hey guys! Here i got an extract of my homework and on this part i always get an error, whether i use toString() and parse it to int or i do it as it stands here: public void fahren(int km) { if (km < 0) { System.out.println("RUECKWAERTSGANG!!!"); km = -km; } if (kmVerbrauch * km > kraftstoffVorrat) { km = Math.round(kraftstoffVorrat / kmVerbrauch).intValue(); // HERE IS THE PROBLEM System.out.println("Zu wenig Sprit!\nAuto kann nur " + km + " Kilometer weit fahren."); } kmStand += km; kraftstoffVorrat -= km * kmVerbrauch; } I always get the 'cannot be dereferenced' error, it's freaking me off, why the hell has someone scripted this f***ing method when it doesn't work? i just want a double to be converted into int, or a long converted into int, is it that difficult!? Not easy to find, you did not post your variable delcaration: kmStand, krafstoff, kmVerbrauch You didn't told us at which line was your error But based on the partial error message you posted I'll bet that you are using Long instead of long A capital L might make a big difference Was This Post Helpful? 0 Back to top MultiQuote Quote + Reply #3
1 to 3 of 3 Thread: Help!! error message "long cannot be dereferenced" LinkBack LinkBack URL About LinkBacks Thread Tools Show Printable Version Email this compareto double java Page… Subscribe to this Thread… Search Thread Advanced Search Display Linear Mode double class java Switch to Hybrid Mode Switch to Threaded Mode 11-30-2008,01:10 PM #1 soc86 Member Join Date Oct 2008 Posts long to string java 39 Rep Power 0 Help!! error message "long cannot be dereferenced" I keep getting an error message stating "long can not be dereferenced", I need the barcode all numbers to http://www.dreamincode.net/forums/topic/143470-long-cannot-be-deferenced-error/ complete my assignment, any advise please? public class Product{ public static void main (String[]arg){ String manufact; String descript; long barCode; int price; int qty; System.out.println("Please enter the manufacturer of your product "); manufact=UserInput.readString(); System.out.println("Please enter the a description of the product "); descript=UserInput.readString(); System.out.println("Please enter the bar code "); barCode=UserInput.readLong(); System.out.println("Please enter the price of your product "); price=UserInput.readInt(); System.out.println("Please enter the quantity http://www.java-forums.org/new-java/13799-help-error-message-long-cannot-dereferenced.html of the product you wish to purchase "); qty=UserInput.readInt(); if (manufact.length()==0){ System.out.println("Error invalid input - manufacturer is blank"); } else if (descript.length()==0){ System.out.println("Error invalid input - description is blank"); } else if (barCode.length()<12){ System.out.println("Error invalid input - bar code is to small"); } else if (barCode.length()>14){ System.out.println("Error invalid input - bar code is to big"); } else if (qty.length()<=0){ System.out.println("Error invalid input - quantity is not entered"); } else{ System.out.println(manufact); System.out.println(descript); System.out.println(barCode); System.out.println(qty); } } } Reply With Quote 11-30-2008,01:30 PM #2 Supamagier Senior Member Join Date Aug 2008 Posts 384 Rep Power 9 As far as I know, you can't do this Java Code: barCode.length() Same for qty.length(). Use Java Code: String.valueOf(barCode).length() Same for qty. ~Matt I die a little on the inside... Every time I get shot. Reply With Quote 11-30-2008,04:24 PM #3 CJSLMAN Moderator Join Date Oct 2008 Location Mexico Posts 1,159 Rep Power 10 Suggestions Are you trying to find out how many numbers there are in the barcode amount/number? Also, why not initialize qty = 0, and then later check if qty == 0? Java Code: String m
details. Win a copy of Penetration Testing Basics this week in the Security forum! Post Reply Bookmark Topic Watch Topic New Topic programming forums Java Java JSRs Mobile Certification Databases Caching http://coderanch.com/t/536655/java/java/int-dereferenced-error Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: Beginning http://coderanch.com/t/519820/java/java/Java-Double-dereferenced Java int cannot be dereferenced error Collete Williams Greenhorn Posts: 4 posted 5 years ago I know this error has been written numerous times, but I am still confused about why I received the error. I am very new to Java, this is my first and last programming class. This cannot be is the first time I have seen this error and lost. I know it has something to do with the int and string. I am confused all together how it works. Code is suppose to accept an integer from user, go thru the array and find the element of that array and display in a textfield. It also has to handle 2 specific exceptions. Can cannot be dereferenced someone please tell me what it is suppose to look like. Thank you.. int cannot be dereferenced-line 53 //import java.lang.*; public class showElement implements ActionListener{ public void actionPerformed(ActionEvent e){ randomNumber = new int [100]; for (int x = 0; x < randomNumber.length; x++) randomNumber[x] = (int)(Math.random() * 1000); String inputString; inputString=valueField.getText(); try{ valueField.setText(randomNumber[Integer.parseInt(inputString)].toString());//error section } catch (IndexOutOfBoundsException ex){ valueField.setText("Out of bounds"); } catch (NumberFormatException ex){ valueField.setText("Not a Integer."); } } } Kurt Van Etten Ranch Hand Posts: 98 posted 5 years ago 1 Hi Collete, and welcome to the Ranch! The error you're getting, in line 17 of the code excerpt you posted, is because you're trying to call the toString() method on an int (since that's what's stored in the array), and int is a primitive type. There are several ways you could convert the int to a String: for example, you could concat it with an empty string to have it implicitly converted, or you could use the static Integer.toString() method to explicitly convert it . Collete Williams Greenhorn Posts: 4 posted 5 years ago I read up on on what it means to "concat it with an empt
Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums Forum: Java in General Java Double cannot be dereferenced Megan Hart Greenhorn Posts: 6 posted 5 years ago Hi All, I am very new to Java and I am getting a 'Double cannot be dereferenced' error when I try to compile this code. public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == exitButton) System.exit(0); else if (source == calculateButton) { double sideAValue = Double.parseDouble(sideAField.getText()); double sideBValue = Double.parseDouble(sideBField.getText()); double sideCValue = Math.hypot(sideAValue, sideBValue); sideCValue.setText(Double.toString(sideCValue)); The above section of code is part of a larger program that calculates the hypotenuse of a right triangle when the user enters the two smaller sides. The error comes from this line of code: sideCValue.setText(Double.toString(sideCValue)); Could someone please help me to know how to fix this? Christophe VerrĂ© Sheriff Posts: 14691 16 I like... posted 5 years ago Shouldn't that be sideCField.setText(Double.toString(sideCValue)); [My Blog] All roads lead to JavaRanch Christophe VerrĂ© Sheriff Posts: 14691 16 I like... posted 5 years ago And welcome to the ranch Next time you want to post some code, don't forget to UseCodeTags. This will be make it easier to read. [My Blog] All roads lead to JavaRanch Megan Hart Greenhorn Posts: 6 posted 5 years ago Yes it should be! Thanks for alerting me to that error. I will be sure to use code tags next time around! Thanks for the welcome! Post Reply Bookmark Topic Watch Topic New Topic Similar Threads creating a new JPanel from another JPanel "choice" button Double compiler error - Help! Help w/ Data Input Error Double compiler error - Help! Not being able to compile All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter Contact Us | advertise | mobile view | Powered by JForum | Copyright © 1998-2016 Paul Wheaton