Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Can anyone tell me why this is null?  RSS feed

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been looking at it forever. Either the following two lines are null according to the exception, but I have been looking for at least 2 hours...i dont get it


or


Here is the code
College:


Catalog


Student


Major


Main


Finally
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im thinking now its my String studentName in this method, but I dont know why

 
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want to happen if m does equal null?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what I get when I try to show a student
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:What do you want to happen if m does equal null?



Probably print an error, but I dont think thats whats causing my current null
 
Marshal
Posts: 5928
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Split that offending line (shown in stack-trace as line 86 I think) to several lines, you'll know exactly what is null.

i.e.
majorName.setText(s.getMajor().getName());

to:
Type t = s.getMajor();
Type t1 = t.getName();

majorName.setText(...);

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what I got...not sure if split those thing correctly
 
Liutauras Vilda
Marshal
Posts: 5928
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what is at line 91 in StudentInfo?!?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, still not sure its either the getName or my studentName


lines 91


line 88
 
Liutauras Vilda
Marshal
Posts: 5928
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So t is null. Which is the result after calling getMajor() I guess. Carey already mentioned correctly where the root problems most likely start.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just dont see it.........
 
Carey Brown
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When in doubt start adding some print statements in in order to see what the program is actually doing.
 
Liutauras Vilda
Marshal
Posts: 5928
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So you have this code which trying to set Major, which is initially null at line 4 (in my snippet). Now you are trying to obtain the major from the Catalog based on major's name. So in case name is found within the catalog you assign it to major.

But in case it is not found within the catalog, what's then? major is left with null value.

Is clear?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well then I am even more lost I have a list of students like
Cody, Biggs, Computer Programming

and the majors in my list look like
Computer Programming
Database
and so on

so when Student gets my students major from the constructor, and when the major is Computer Programming, and the major in the catalog is Computer Programming..how am I getting a null?

 
Carey Brown
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
LoadMajors() does not appear to be called from anywhere.

What does your majors file look like?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
load majors is in my main app


my majors file looks like Computer Programming,true,ENG-101,CPT-102,CPT-167,CPT-187,CPT-172,CPT-242,IST-272,CPT-237,CPT-244,CPT-239,IST-238,CPT-270,MGT-270,MAT-110,CPT-262,ACC-101,IST-190,CPT-283,IST-204,CPT-210

but load majors only takes the first line, so it would be Computer Programming, Database, Accounting...and so on
 
Carey Brown
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't see that call in the Main class you posted. Have you modified the code since posting?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


 
Liutauras Vilda
Marshal
Posts: 5928
411
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are at the stage when you really need to pick up testing framework (JUnit not a bad option) and start testing each of your classes along with each of their methods.

Now you have a bunch of lines of code, and you don't know where the things start falling apart. That leads to desperate decisions and chaos in a code. I've experienced that many times already. To cut corners and write production code ("to speed up things") proves to be a bad decision almost always.
 
Sheriff
Posts: 5023
138
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would try this:
Then see which major name is the problem (problems?)
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed it. Or you could say found a way around it. Still works the way I want it to the only problem is im not reading from a file for the students loaded in. Instead I just set the major to "undeclared", and later in the program the students have the option to change that.

So now for my next question...sorting. For some reason this has been a real struggle for me, although I sorted everything right for my previous assignment. For this one I just want the arrayList<Students> sorted, so when the list view loads up all the names are sorted. Problem is that my student class holds no first name, last name they get that from the Person Class which they inherit. Both student and instructor inherit Person, but thats not important right now. I tried making person implement Comparable<student> but fussed that forst name is not visible as its set to private. Do I want to make that public for the sorting? Or is it better left private? Then I tried implementing a comparable<Student> in Person but when I did


It fussed that - is undefined for them. I just want to sort by firstName, simple sort. am I doing it in the wrong Class? I just thought since they get everything from Person that, thats where it should be

Here are my classes just incase. The person only shows the first name in the listView because of ways I had to return the names. Doesnt matter whats showing just as long as I have a sort, and the full student is shown when selected from the list. Again probably not Important
Person


Student


College where the student list is loaded

 
Master Rancher
Posts: 3257
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

- is undefined for ...


That's right.  There is no - operator for String objects.  The + operator was grandfathered in because of C to allow quicker coding.

The String class has a method for comparing two Strings that returns an int value you can use in your method.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, here would I put it? My person Class now looks like



and the array is in the College class I tried. But I get red lines that say "Delete )", "Delete (", and " = expected"
 
Norm Radder
Master Rancher
Posts: 3257
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I get red lines that say "Delete )", "Delete (", and " = expected" 


Can you compile the code and copy the text of the compiler's error message and paste it here.
What you posted does not make sense to me.

Please copy full text of the compiler's error message and paste it here.
The message should show the source with a ^ under the location of the error.
Here is a sample from the javac compiler:
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive never seen that... but on the line my collections.sort it says
Multiple markers at this line
- Syntax error on token ",", = expected
- Syntax error on token "(", Identifier
expected
- Syntax error on token ")", delete this
token
 
Norm Radder
Master Rancher
Posts: 3257
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Multiple markers at this line 


The problem is we can not see "this line".

The posted error message needs to include the full text of the line and its line number.
 
Master Rancher
Posts: 2758
93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that I lost track of your application, I might talk nonsense or about things that were rejected some time ago, but here is how I probably would tackle the sorting problem:

1) I have the Person class with two protected members, firstName and lastName, and that class implements Comparable<Person>

2) I have the Student class that extends Person, with the extra member id, and a public method that retuns a Comparator<Student> that compares on id, for every class available that is interested.

and I wrote an SSCCE, with the classes divided over three packages:



Perhaps this could simplify your code somewhat, or make it more clear where to put the stuff. By the way, it is strongly recommended to also override the equals and hashCode methods, but that for some other time.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The line is my collections.sort(students, new Person.firstNameSorter()); in the college class. So line 34

College class
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it by turning it into a button and using a lamda expression
 
Norm Radder
Master Rancher
Posts: 3257
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like line 34 is not inside of a method. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!