Another Java Project Problem

Rock Raiyu

Clock Up
OP
Member
Joined
Jul 14, 2007
Messages
5,066
Trophies
1
Age
32
Location
Walking the path of heaven
XP
2,359
Country
United States
For some reason, I can't compile my program I keep getthing the same error and for the life of me I can't figure out this problem. Here is my code, it has 3 parts to it which I've labeled.

http://pastebin.com/4ftMFk3K

Error is "Exception in thread "main" java.util.Input Mismatch Exception"

And the errors have to do with my scanner class. I can't post it here, as it apparently has long words..
 

caster62003

Well-Known Member
Member
Joined
Nov 22, 2008
Messages
111
Trophies
0
XP
85
Country
United States
Would it be possible to get the elev.txt file? I tossed your code into an Eclipse project, it compiles just fine, but when I run it, I get an exception that elev.txt is missing. So without that, I cannot debug very easily, if at all.

If you do not wish to share your elev.txt file, knowing what you said, and what I see on my end, I would say the issue lies more than likely in the elev.txt file. If I were you, I would setup some breakpoints in the ElevatorTest.java file in your do while loop, and check what is in the scanner for each time something is read from it. Also determine how much the scanner reads in before the exception occurs, does it get the Name? Weight? is it later on in the file it crashes? Are you missing a space in the file?

Aslo, a few minor cretiques, nothing that will solve the problem, but why do you have the main class throwing exceptions? What is possibly going to pick that up? Instead of this, use try a try catch block, also, your count variable is never used, at all, I would remove that. You are also missing comments, I would make sure to add those in. I don't know if this is just for personal gain, or if you will be graded on it, but I know if I would submit this to my professors, I know I would be docked for those issues.
 

Rock Raiyu

Clock Up
OP
Member
Joined
Jul 14, 2007
Messages
5,066
Trophies
1
Age
32
Location
Walking the path of heaven
XP
2,359
Country
United States
I posted a link for all the files for my project.

http://cse.spsu.edu/proth/1301/Projects/1301Proj5elevator.doc

That's the link to the project that she assigned.

And yeah I know its a rough draft cause I started working on it Sunday, knowing its due this Wednesday. So its missing some things and has some things that need to be removed. I'll keep your critique in mind when I finish it up.

http://www.mediafire.com/?25enojbi78vqbm4
 

caster62003

Well-Known Member
Member
Joined
Nov 22, 2008
Messages
111
Trophies
0
XP
85
Country
United States
I'll give you a hint, it doesn't crash in the do while loop, it crashes right after the scanner is made, and you ask for an integer to be stored into s, which then causes the whole thing to blow up, and causes the exception. I have no idea what all the variables mean, and what they are supposed to represent, which is why I recommend adding some comments, so if you want to, add some comments, and I'll take another whack at it, but at this point, there is your problem, hope it helps.

On a random side note, does your teacher not know the days of the week and their order? I never knew Tuesday came after Wednesday... :P
 

purplesludge

anyone have any ideas for this space
Member
Joined
Mar 2, 2009
Messages
1,047
Trophies
0
Age
34
Location
wv
Website
Visit site
XP
260
Country
United States
The problem with your scanner was the string before the number.
I fixed that and made some changes that I think would work better. The main one is using an arrays to store the values from the text file, then working with the arrays instead of the file.

I didn't change anything past line 25.

http://www.mediafire.com/?7lsplool9znnl84
 
Solution

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    K3Nv2 @ K3Nv2: People's funny bones are the same taste indeed