• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compile errors from textbook source code

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I've visited these forums before looking for help years ago and received great help and advice and now that I'm having trouble again I thought I would ask again. My problem is that for part of an assignment I'm supposed to download the source code for examples that were given in the text book. I'm then supposed to write a program to count the number of commands but first I can't get the source code to compile without errors. I'm not sure what the two errors I'm getting really mean and haven't found a clear answer while searching online. The source code can be found Here. It's the link called source code under the sample materials tab. I'm specifically using the code from chapter 1.

Now when I compile StringSorter.java I get the following error:


The second error occurs when I compile TestStringSorter.java:


Now since they are all source code from the text book I would assume they are correct and I'm missing something used to compile them.
For the second error I believe it has to do with junit. I'm not sure what that really is, is it something seperate from the JDK you download from the Oracle website?

And the first error seems to be a string being passed an object and it can't take that variable type? I'm really confused.


Note*: I haven't coded in several years because I had to stop going to school to work full time. I had to bills to pay and needed to eat. I now wish I had stayed up on it while out of school. Either way, please be gentle with me and I appreciate any and all help give.
 
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's kind of a lot of code to plow through, but I note the programmer has simply cast the reference returned by the get method to type String in the immediate neighborhood of the error. Try that and see if it works.

That is, change this:


to this:

 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it might work much better above that, to change this:



to this:


I'm not utterly at home with generics yet, though, so someone else may want to chime in.
 
Andrew Whitworth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did the suggested change for the first compile error and that allowed it to compile. However, I'm still having the compile error for the TestStringSorter.java that says it can't find the junit.framework.TestCase. Do you know what junit is? Why it possibly can't locate it?


As for the first error, was it just a syntax error? Was String supposed to be there in the first place? Are there any instances where I wouldn't have to specify if it was a String?

EDIT: Your second option allows it to compile as well. So, if I understand correctly something with .compareTo doesn't like l.get(i) not being specified that it's a String?


Sorry if the questions are mundane or annoying, I'm just trying to fully understand what went wrong and how the correction has resolved the issue (so far).
 
Stevens Miller
Bartender
Posts: 1464
32
Netbeans IDE C++ Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Whitworth wrote:I did the suggested change for the first compile error and that allowed it to compile. However, I'm still having the compile error for the TestStringSorter.java that says it can't find the junit.framework.TestCase. Do you know what junit is? Why it possibly can't locate it?



What does your textbook say about junit?



As for the first error, was it just a syntax error? Was String supposed to be there in the first place? Are there any instances where I wouldn't have to specify if it was a String?



I'd call it a plain old programming error. List objects can hold references to any kind of object. You either have to declare what type they hold when you create the List object (my second approach), or else cast the objects returned by the List methods to the type you know they are (my first approach). Neither was done here, so it didn't work. Nothing more to it than that.

Disappointing that a textbook has (what must be) untested code in it, but it happens.
 
Andrew Whitworth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What does your textbook say about junit?




Nothing, this is a intro to Software Engineering course/book so I"M assuming that THE AUTHOR is assuming I know what it is lol. I never encountered it before in my java programming books so I think it's separate from oracles JDK. I think I've found what I'm looking for online, a tutorial on junit that should show me how to install it and utilize it. If anyone has any clarification on the matter I would appreciate it. I will respond if it solves the issue.


As a side note, any suggestions on the best way I should go about brushing up on my java skills (which are rather basic)? I've thought about just reading through my old textbooks but that seems like it would be less efficient time-wise.


Quick Edit: I downloaded junit from Sourceforge (I don't know if there is an official website or not for junit) unzipped it, placed it in my java folder next to the jre7 folder and then just added the classpath using this tutorial. Everything compiled but I haven't had a chance to test it. I will do so when I return home.
 
Andrew Whitworth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So everything compiles like I said but when I run StringSorterGui.java it askes for an input and out put file. I created two notepad files, one called 'Input' with a random string and another blank file called 'Output.' I navigate to them and select them and then click the sort button. Then if I check the Output file I created all that has happened is that it copied the string from Input into Output without sorting it.

So I'm left to believe there is some error with the StringSorter class but I can't find anything. I was wondering if you can see anything that may stand out.
 
Andrew Whitworth
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel absolutely retarded. I forgot to put my strings on new lines in the input file. Derp. Thanks again for all the help. I'm marking this as solve now. I really appreciate the help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic