|
|||
|
I've finally got around to compiling my program with -Xlint, as the compiler
kept nagging me to. This is what I got. (I've removed some entries for different bits that caused identical errors.) I haven't a clue what any of it means or what to do about it; can anyone enlighten me? What's a raw type, for instance, and what's a serializable class and how do you give it a definition of serialVersionUID? ---------------------------------------------- Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox JComboBox droplist = new JComboBox(); ^ missing type arguments for generic class JComboBox<E> where E is a type-variable: E extends Object declared in class JComboBox Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox JComboBox droplist = new JComboBox(); ^ missing type arguments for generic class JComboBox<E> where E is a type-variable: E extends Object declared in class JComboBox Vectorine.java:68: warning: [unchecked] unchecked call to addItem(E) as a member of the raw type JComboBox droplist.addItem("Compare to what?"); ^ where E is a type-variable: E extends Object declared in class JComboBox Vectorine.java:71: warning: [unchecked] unchecked call to addItem(E) as a member of the raw type JComboBox droplist.addItem("Other planet"); ^ where E is a type-variable: E extends Object declared in class JComboBox Vectorine.java:143: warning: [static] static method should be qualified by type name, DatasetReader, instead of by an expression datareader.getPlanetPositions(planet); ^ Vectorine.java:145: warning: [static] static variable should be qualified by type name, DatasetReader, instead of by an expression for (int count=0; count<datareader.planetPositions.length; count++) ^ Vectorine.java:21: warning: [serial] serializable class Vectorine has no definition of serialVersionUID public class Vectorine extends JFrame implements ItemListener, MouseListener ^ ---------------------------------------------- (DatasetReader is another class in my program, which the main class creates an instance of so it can use its methods to look up data. Anything else I should explain, just tell me.) -- Many thanks, A. B. ><> My e-mail address is zen177395 at zendotcodotuk, though I don't check that account very often. Post unto others as you would have them post unto you. |
|
|
||||
|
||||
|
|
|
|||
|
On Sunday, February 12, 2012 8:16:44 AM UTC-8, A B wrote:
> I've finally got around to compiling my program with -Xlint, as the compiler > kept nagging me to. This is what I got. (I've removed some entries for > different bits that caused identical errors.) I haven't a clue what any of > it means or what to do about it; can anyone enlighten me? What's a raw > type, for instance, and what's a serializable class and how do you give it a > definition of serialVersionUID? You need to read the Java tutorials before you code. <http://docs.oracle.com/javase/tutorial/index.html> Every single one of those terms is eminently searchable, did you but take the effort to do so: <http://lmgtfy.com/?q=Java+raw+type> The first result of which points to the Java Language Specification, which has an entire section on raw types: <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#110257> The tutorial explains your problem: <http://docs.oracle.com/javase/tutorial/extra/generics/legacy.html> "When a generic type like Collection is used without a type parameter, it's called a raw type." You need to read the Java API docs as you code. <http://docs.oracle.com/javase/7/docs/api/> If you look at the docs for 'JComboBox' you will see that it's a generic type: <http://docs.oracle.com/javase/7/docs/api/javax/swing/JComboBox.html> You neglected to specify the item type for the combo box. You show us none of your code, for shame, but clearly you defined your class as 'implements Serializable' ('implements java.io.Serializable'). This is in your code, so presumably you looked up the API docs for 'Serializable' and read them thoroughly. Otherwise, why did you use it? A "serializable class" is one defined that it 'implements Serializable', and in the Javadocs for that interface they explain about 'serialVersionUID'. Read it. <http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html> Then, do not use 'Serializable'. Do not use it. Stop using it. Until you have purchased and studied /Effective Java/ (2nd ed.) by Joshua Bloch. <http://java.sun.com/docs/books/effective/> which devotes its entire Chapter 11 to serialization and 'Serializable'. You must not use Java serialization until you properly understand it! /Effective Java/ has the best explanation of serialization, its dangers (of which there are many) and how to circumvent them. Next time, post an SSCCE. http://sscce.org/ > ---------------------------------------------- > Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox > JComboBox droplist = new JComboBox(); > ^ > missing type arguments for generic class JComboBox<E> > where E is a type-variable: > E extends Object declared in class JComboBox The message is pretty darned clear. You are missing the type arguments. So add type arguments! See the Javadocs, linked above. > ... > Vectorine.java:21: warning: [serial] serializable class Vectorine has no > definition of serialVersionUID > public class Vectorine extends JFrame implements ItemListener, MouseListener > ^ > ---------------------------------------------- Don't declare the class 'Serializable'. > (DatasetReader is another class in my program, which the main class creates > an instance of so it can use its methods to look up data. Anything else I > should explain, just tell me.) Stop the hand waving. If code is relevant, show the code, don't just describe it. http://sscce.org/ In your case, the problem is not in the code but in insufficient study beforehand. Read the tutorial before setting finger to keyboard to code again. *LOOK UP* terms that you don't recognize! Read the Javadocs. GIYF. -- Lew |
|
|||
|
On 2/12/2012 8:16 AM, A B wrote:
> I've finally got around to compiling my program with -Xlint, as the > compiler kept nagging me to. This is what I got. (I've removed some > entries for different bits that caused identical errors.) I haven't a > clue what any of it means or what to do about it; can anyone enlighten > me? What's a raw type, for instance, and what's a serializable class and > how do you give it a definition of serialVersionUID? > ---------------------------------------------- > Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox > JComboBox droplist = new JComboBox(); > ^ > missing type arguments for generic class JComboBox<E> > where E is a type-variable: > E extends Object declared in class JComboBox > > Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox > JComboBox droplist = new JComboBox(); > ^ > missing type arguments for generic class JComboBox<E> > where E is a type-variable: > E extends Object declared in class JComboBox > > Vectorine.java:68: warning: [unchecked] unchecked call to addItem(E) as > a member of the raw type JComboBox > droplist.addItem("Compare to what?"); > ^ > where E is a type-variable: > E extends Object declared in class JComboBox > > Vectorine.java:71: warning: [unchecked] unchecked call to addItem(E) as > a member of the raw type JComboBox > droplist.addItem("Other planet"); > ^ > where E is a type-variable: > E extends Object declared in class JComboBox > > Vectorine.java:143: warning: [static] static method should be qualified > by type name, DatasetReader, instead of by an expression > datareader.getPlanetPositions(planet); > ^ > Vectorine.java:145: warning: [static] static variable should be > qualified by type name, DatasetReader, instead of by an expression > for (int count=0; count<datareader.planetPositions.length; count++) > ^ > > Vectorine.java:21: warning: [serial] serializable class Vectorine has no > definition of serialVersionUID > public class Vectorine extends JFrame implements ItemListener, > MouseListener > ^ > ---------------------------------------------- > (DatasetReader is another class in my program, which the main class > creates an instance of so it can use its methods to look up data. > Anything else I should explain, just tell me.) > -- > Many thanks, > A. B. >> <> > My e-mail address is zen177395 at zendotcodotuk, though I don't check > that account very often. > Post unto others as you would have them post unto you. I can tell you are using Java 7, JComboBox has changed to a generic class. The simple answer is if you are creating a JComboBox of Strings, declare it thus; JComboBox<String> box = new JComboBox<String>(String[] items) -- Knute Johnson |
|
|||
|
Knute Johnson wrote:
> A B wrote: > > I've finally got around to compiling my program with -Xlint, as the > > compiler kept nagging me to. This is what I got. (I've removed some > > entries for different bits that caused identical errors.) I haven't a > > clue what any of it means or what to do about it; can anyone enlighten > > me? What's a raw type, for instance, and what's a serializable class and > > how do you give it a definition of serialVersionUID? > > ---------------------------------------------- > > Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox > > JComboBox droplist = new JComboBox(); > > ^ > > missing type arguments for generic class JComboBox<E> > > where E is a type-variable: > > E extends Object declared in class JComboBox .... > I can tell you are using Java 7, JComboBox has changed to a generic > class. The simple answer is if you are creating a JComboBox of Strings, > declare it thus; > > JComboBox<String> box = new JComboBox<String>(String[] items) Or, since it's Java 7, JComboBox<String> box = new JComboBox<>(items) (The 'String[]' in an invocation is an error. It is useful to show a possible type for the argument, but is not compilable as such. So, "A B", be sure to vet any code before blindly copying and pasting. Usenet code posts are often, as above, actually pseudocode.) -- Lew |
|
|||
|
On 2/12/2012 9:07 AM, Lew wrote:
> Knute Johnson wrote: >> A B wrote: >>> I've finally got around to compiling my program with -Xlint, as the >>> compiler kept nagging me to. This is what I got. (I've removed some >>> entries for different bits that caused identical errors.) I haven't a >>> clue what any of it means or what to do about it; can anyone enlighten >>> me? What's a raw type, for instance, and what's a serializable class and >>> how do you give it a definition of serialVersionUID? >>> ---------------------------------------------- >>> Vectorine.java:39: warning: [rawtypes] found raw type: JComboBox >>> JComboBox droplist = new JComboBox(); >>> ^ >>> missing type arguments for generic class JComboBox<E> >>> where E is a type-variable: >>> E extends Object declared in class JComboBox > ... > >> I can tell you are using Java 7, JComboBox has changed to a generic >> class. The simple answer is if you are creating a JComboBox of Strings, >> declare it thus; >> >> JComboBox<String> box = new JComboBox<String>(String[] items) > > Or, since it's Java 7, > > JComboBox<String> box = new JComboBox<>(items) > > (The 'String[]' in an invocation is an error. It is useful to show a possible > type for the argument, but is not compilable as such. So, "A B", be sure to vet > any code before blindly copying and pasting. Usenet code posts are often, as > above, actually pseudocode.) > True, I pulled it from the Docs, and I did forget that you don't need to specify the type on the right. -- Knute Johnson |
|
|||
|
Knute and Lew - thanks very much for explaining how to fix the "raw type"
error. I've finally found out how to fix the other two, but it took me a LONG time because I'm doing my programming on a computer without an Internet connection, and for some bizarre reason that seems to mean I can't search the documentation or use the tutorials. Didn't know where to look in the contents because I didn't know what the problem was. It's like looking in a dictionary to find out how to spell something! (My Internet computer is a laptop with a fixed, daft refresh rate that stops me concentrating.) THAT's why I asked. Roedy - I've saved those pages to look at later. May just be me, but they look much more intelligible than the stupid Javadocs on the same topics. Sorry I didn't post the code, only I didn't have enough idea where the error was coming from to do a SSCCE, and the full code would have made the posting about three feet long! -- A. B. ><> My e-mail address is zen177395 at zendotcodotuk, though I don't check that account very often. Post unto others as you would have them post unto you. |
|
|||
|
On Thursday, February 16, 2012 12:50:17 PM UTC-8, A B wrote:
> Knute and Lew - thanks very much for explaining how to fix the "raw type" > error. I've finally found out how to fix the other two, but it took me a > LONG time because I'm doing my programming on a computer without an Internet > connection, and for some bizarre reason that seems to mean I can't search > the documentation or use the tutorials. Didn't know where to look in the > contents because I didn't know what the problem was. It's like looking in a > dictionary to find out how to spell something! (My Internet computer is a > laptop with a fixed, daft refresh rate that stops me concentrating.) THAT's > why I asked. AFAIK, the tutorials and certainly the API docs are downloadable. Next time you're on the 'Net, download those to a thumb drive and keep that with the laptop. Also, get a better laptop. -- Lew |
|
|||
|
"Lew" <lewbloch@gmail.com> wrote on 16th February:
> On Thursday, February 16, 2012 12:50:17 PM UTC-8, A B wrote: >> Knute and Lew - thanks very much for explaining how to fix the "raw type" >> error. I've finally found out how to fix the other two, but it took me a >> LONG time because I'm doing my programming on a computer without an >> Internet >> connection, and for some bizarre reason that seems to mean I can't search >> the documentation or use the tutorials. Didn't know where to look in the >> contents because I didn't know what the problem was. It's like looking >> in a >> dictionary to find out how to spell something! (My Internet computer is >> a >> laptop with a fixed, daft refresh rate that stops me concentrating.) >> THAT's >> why I asked. > > AFAIK, the tutorials and certainly the API docs are downloadable. Next > time > you're on the 'Net, download those to a thumb drive and keep that with the > laptop. > > Also, get a better laptop. Inclined to agree, but how would you find out which have an adjustable refresh rate (that goes up to anything useful)? This one ought to; it's quite an expensive one. I've got the API docs, it's just that the downloaded copy doesn't seem to have a search function, so it's trial and error. I can't find any downloadable tutorials in the byzantine depths of the website; if you can I'd be very grateful! -- A. B. ><> My e-mail address is zen177395 at zendotcodotuk, though I don't check that account very often. Post unto others as you would have them post unto you. |
|
|||
|
On 02/16/2012 04:44 PM, A B wrote:
> I've got the API docs, it's just that the downloaded copy doesn't seem > to have a search function, so it's trial and error. I can't find any > downloadable tutorials in the byzantine depths of the website; if you > can I'd be very grateful! It's kinda hard to see. Look in the side bar, under "Tutorial Resources" section, the link reads "Download the latest Java Tutorials bundle". <http://docs.oracle.com/javase/tutorial/> |
|
|||
|
"Jeff Higgins" <jeff@invalid.invalid> wrote in message
news:jhk1f2$20k$1@dont-email.me... > On 02/16/2012 04:44 PM, A B wrote: > >> I've got the API docs, it's just that the downloaded copy doesn't seem >> to have a search function, so it's trial and error. I can't find any >> downloadable tutorials in the byzantine depths of the website; if you >> can I'd be very grateful! > It's kinda hard to see. > Look in the side bar, > under "Tutorial Resources" section, > the link reads "Download the latest Java Tutorials bundle". > <http://docs.oracle.com/javase/tutorial/> Hey, thanks! Could have sworn I'd looked there. -- A. B. ><> My e-mail address is zen177395 at zendotcodotuk, though I don't check that account very often. Post unto others as you would have them post unto you. |
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|