Unusual Error Message PLZ HELP
Author |
Message |
shlubster
|
Posted: Mon Sep 08, 2008 5:25 pm Post subject: Unusual Error Message PLZ HELP |
|
|
Hi
I am new to the java programming language
( 1 month of on and off programming and now im really trying to learn)
and when i was programming i got this error in my output area when trying to execute a program
i am using JCreator LE
--------------------Configuration: <Default>--------------------
How Old are You?
12
Do you have a coupon? (Y/N)
Exception in thread "main" java.lang.NullPointerException
at TicketDiscout.main(TicketDiscout.java:23)
Process completed.
If you recognize this error please help, if you need my full code then tell me
Thanks |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Insectoid

|
Posted: Mon Sep 08, 2008 5:33 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
Yes, we really need your code (I don't even know Java, and I know we need your code). Giving us the output doesn't matter, we can figure out the output on our own (well, not me, but people who know Java)
I suppose you broke some rule or other in the language...
Anyways, hope somebody comes along and helps you! |
|
|
|
|
 |
btiffin

|
Posted: Mon Sep 08, 2008 5:56 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
Hi,
Yep, we'll need to see the code. And as it turns out, a null pointer exception is not that unusual. Not during development at least.
Line 23 inside TicketDiscount.java is trying to access something through a variable that isn't pointing anywhere.
Cheers,
Brian
P.S. When you post your code, use bbcode code tags.
code: |
They look like [code] ... [/code]
|
|
|
|
|
|
 |
Witchcraft
|
Posted: Mon Sep 08, 2008 8:24 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
Shlubster, are you by any chance the friend of the really good programmer who goes by the name whos the who? He mention something about you. If your half as good as him, then I can't wait to see what kinds of programs you can write. I love his games, the last one he posted was amazing, the graphics aren't that great but its deep, and I might even say that I prefer it over games like bioshock, call of duty, and crysis! Anyways let me know soon. |
|
|
|
|
 |
syntax_error

|
Posted: Mon Sep 08, 2008 8:31 pm Post subject: Re: RE:Unusual Error Message PLZ HELP |
|
|
Witchcraft @ Mon Sep 08, 2008 8:24 pm wrote: Shlubster, are you by any chance the friend of the really good programmer who goes by the name whos the who? He mention something about you. If your half as good as him, then I can't wait to see what kinds of programs you can write. I love his games, the last one he posted was amazing, the graphics aren't that great but its deep, and I might even say that I prefer it over games like bioshock, call of duty, and crysis! Anyways let me know soon.
There is a pm system for this type of messages, the topic area is not a chat room.
Please do not take this in a harsh manner. |
|
|
|
|
 |
Witchcraft
|
Posted: Mon Sep 08, 2008 9:02 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
my mistake, I thought I clicked pm, but I must not have loaded the page, and I didn't realize, causing me to post on the thread. Once again sorry about that irrelevant comment, (it was suppost to be a joke, cause he actually knows me)
anyways back on topic, these two previous commenters are right. YOU NEED TO SHOW YOUR CODE IF YOU WANT HELP! |
|
|
|
|
 |
shlubster
|
Posted: Tue Sep 09, 2008 7:42 pm Post subject: Re: Unusual Error Message PLZ HELP |
|
|
Hey
this is my code
code: | /**
* @(#)TicketDiscount.java
*
*
* @author
* @version 1.00 2008/9/9
*/
import java.util.Scanner;
public class TicketDiscount {
public static void main(String args[]) {
Scanner Scan = new Scanner(System.in);
int age;
double price = 2.00;
char reply;
System.out.println("How old are you?");
age = Scan.nextInt();
System.out.println("Do you have a coupon? Y/N");
reply = Scan.findInLine(".").charAt(0);
if (age >= 12 && age <65) {
price=9.25;
}
if (age<12 || age >=65){
price=5.25;
}
if ((reply=='y' || reply=='Y') && age>12 || age<65) {
price-=2.00;
}
}
} |
thanks for the help |
|
|
|
|
 |
Insectoid

|
Posted: Tue Sep 09, 2008 9:12 pm Post subject: Re: RE:Unusual Error Message PLZ HELP |
|
|
btiffin @ Mon Sep 08, 2008 5:56 pm wrote: Hi,
P.S. When you post your code, use bbcode code tags.
code: |
They look like [code] ... [/code]
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
btiffin

|
Posted: Wed Sep 10, 2008 12:08 am Post subject: Re: Unusual Error Message PLZ HELP |
|
|
Umm,
findInLine(".") ok, I can't find the details of the regex and bounds that findInLine is using and what it returns. I'd guess null or some other rot. Yep. Just found it. The change occurred between 1.5 and 1.6 implementations of findInLine.
Your code would work with Java 1.5 (or Java 5 as some may call it - which I find a little bogus, seeing as it's all still version 1 of the language - but that is just an old guy rambling complaint - deluding people to think that it's ooohh so advanced - bogus I say).
A suggested fix would look like
code: | reply = Scan.findWithinHorizon(".",0).charAt(0); |
But I'd rework that even. It'll be a good exercise. Try and simplify the expression to something you feel comfortable reading.
Cheers |
|
|
|
|
 |
shlubster
|
Posted: Wed Sep 10, 2008 6:18 pm Post subject: Re: Unusual Error Message PLZ HELP |
|
|
Hey
What is BBcode Code tags?
Thanks |
|
|
|
|
 |
Insectoid

|
Posted: Wed Sep 10, 2008 6:38 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
They are little bits of code you type into your message that do things like underlining, italics, bold, colors, code, syntax, and more. Thy usually go like this
[effect]stuff here gets affected[/effect]
For example:
for green text, type (color=green) and (/color), but with [], not (). |
|
|
|
|
 |
Zren

|
Posted: Wed Sep 10, 2008 6:39 pm Post subject: Re: Unusual Error Message PLZ HELP |
|
|
Enter this in your message surrounding code:
code: | [code] ...int foo = 666;...[/code] |
It's purpose is for others to be able to read your program source easier. |
|
|
|
|
 |
Insectoid

|
Posted: Wed Sep 10, 2008 6:40 pm Post subject: RE:Unusual Error Message PLZ HELP |
|
|
darn it Zren, I was editing my post! Now the BBcode doesn't work and I look bad! People these days...(Sarcasm) |
|
|
|
|
 |
btiffin

|
Posted: Wed Sep 10, 2008 8:37 pm Post subject: Re: Unusual Error Message PLZ HELP |
|
|
shlubster;
The next time you post, check beside the Font Colour ... Font face buttons. You'll see More Tags
Hover over any of the entries, and just above the text edit area, the system will show you what to type to get that special effect. If you click, the system will insert the tags, but you usually have to muck around to get the ending tag in the right place. I usually just type them where I want them, but the hover can give you the hints of what is available.
For instance, to get the bold More Tags, I used BBCode was invented to allow us to use cool brower HTML, without some of the associated risk. HTML hypertext Anchor, and properties of many other HTML tags can evaluate scripts or cross link to dodgy sites. PhpBB invented, as far as I know, this safer tag system for general unrestricted public use. They take the BBCode, strip out (disallow) any nasty bits, then translate what is left over to real HTML.
Cheers |
|
|
|
|
 |
|
|