Results 1 to 17 of 17
Thread: new to java - NEED HELP!
- 12-07-2011, 07:32 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
new to java - NEED HELP!
Hello i am new to java and in my java class we just started using classes. I am getting an error in one of my programs saying:
"java.lang.NullPointerException
at LogicOfProgramming.Assignment4.MonthlyCalendar.cal endar(MonthlyCalendar.java:30)
at LogicOfProgramming.Assignment4.MonthlyCalendarAppl ication.main(MonthlyCalendarApplication.java:20)"
Here are my classes:
- 12-07-2011, 07:36 PM #2
Re: new to java - NEED HELP!
Did you google the cause of that Exception?
If you want help, you'll have to provide an SSCCE that demonstrates the problem.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 12-07-2011, 07:42 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
I have googled the problem but I couldn't find exactly what was causeing it... something about me goofing up on a class.... also there are only 3 class files.. i believe thats pretty short?
- 12-07-2011, 07:51 PM #4
Re: new to java - NEED HELP!
I'd be pretty surprised if you couldn't figure out what causes an NPE by a google search, or a search of these forums. And three classes is actually quite huge for this type of problem- you have a line number, right? So you already know the exact line causing the problem. Isolate that line in a standalone program, and copy and paste it here. Don't forget the code tags.
Chances are, in the course of creating your standalone program, you'll figure the problem out on your own. But if not, then many people hesitate to click on .zip attachments, and we don't have time to wade through too much code. Make it easier for people to help you, and you'll get help faster.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 12-07-2011, 08:05 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
NPE? I dont know what that is.
I don't know which parts of the code i need and which parts I wouldn't even with the lines.
I haven't done much codeing in general and i hardly know how to fix bugs. You need to remember ive been doing classes in general about 2days now and my teacher didn't even trully explain it.
- 12-07-2011, 08:14 PM #6
Re: new to java - NEED HELP!
Look at line 30 in the MonthlyCalendar class. There is a variable on that line that has a null value.java.lang.NullPointerException
at LogicOfProgramming.Assignment4.MonthlyCalendar.cal endar(MonthlyCalendar.java:30)
Determine what variable is null and then backtrack in your code and find out why the variable does not have a valid value.
If you can not determine which variable is null, add a println just before line 30 that prints the values of all the variables used on line 30
- 12-07-2011, 08:14 PM #7
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: new to java - NEED HELP!
Date was never initialized in MonthlyCalendar
- 12-07-2011, 08:35 PM #8
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
I thought i just had to put "Date theDate;" in my variable declaration and then i could call on it? Am i wrong?
- 12-07-2011, 08:41 PM #9
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: new to java - NEED HELP!
If an object is not initialized it will be assigned to null.
- 12-07-2011, 08:44 PM #10
Re: new to java - NEED HELP!
There are two steps:
define the variable and
give it a value.
- 12-07-2011, 08:49 PM #11
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
im sorry guys... but i still have no clue what i did wrong T_T im trying to understand what you guys are telling me but sadly half of it is going right over my head... (partially because i don't know the terminology of most of what im actually doing.)
- 12-07-2011, 08:52 PM #12
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: new to java - NEED HELP!
You are passing an initialized Date object to MonthlyCalendars constructor. You have an uninitialized Date object inside MonthlyCalander. Perhaps some kind of assignment can be done inside the the constructor?
- 12-07-2011, 09:01 PM #13
Re: new to java - NEED HELP!
Do you know what an assignment statment is? It is used to give a value to a variable:
x = 123; // assign the value 123 to the variable x
Do you know how to define a variable:
int x; // define an int variable named x
These can be done in one statement:
int x = 123; // define a variable and give it a value.
- 12-07-2011, 09:14 PM #14
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
i don't even call of the MonthlyCalendars constructor though.
- 12-07-2011, 09:16 PM #15
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: new to java - NEED HELP!
hmmmm Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)
Java Code:MonthlyCalendar newMonthlyCalendar = new MonthlyCalendar (newDate);
- 12-07-2011, 09:19 PM #16
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0
Re: new to java - NEED HELP!
Ohhh your right (feels stupid). So what would i put into this constructor? The Date class?
- 12-07-2011, 09:21 PM #17
Member
- Join Date
- Dec 2011
- Posts
- 8
- Rep Power
- 0


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks