7,116 Posted Topics
Re: Yes, you need to forget about arrays. Don't even try to convert to or from arrays. Eliminate all the [] from your code. ArrayLists are different and, for your app, better. Just add your objects the ArrayList and get them with myArrayList.get(index). Loop thru them with for (StoreItem si : … | |
Re: int sum=0, j=0; for (int i =0; i<10; i++) { j +=2; sum += i+j; } (IMHO this is far clearer anyway) | |
Re: Open your jar file with any zip program (a jar is just a .zip) and see if all your other classes and other resources are present and in the right folders etc. Make sure you are catching all exceptions and sending them to System.out (or, better, System.err). | |
Re: Read & study this tutorial [url]http://download-llnw.oracle.com/javase/tutorial/networking/overview/index.html[/url] | |
Re: Oracle is no problem. .net is probably the best choice if, and only if, the environment is completely Windows, and will continue to be exclusively Windows. Although there are ways to run .net on (eg) Linux, it's not a good basis for a production environment If portability is, or may … | |
Re: Have a look at HashMap. It will let you store the 3 letter abbreviation as a key and the one letter abbreviation as a value (map.put(key, vaue)), then it will give you an instant lookup of the vaLue associated with any key (value = map.get(key)); | |
Re: 1. Yes, but its not easy. 2. Dunno, ask in a silverlight/ c# forum. | |
Re: I guess you missed the bit at the head of the main forum listing where it says [QUOTE]We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.[/QUOTE] | |
Re: Are you certain you have a memory leak? Because Java does its own garbage collection the only way to "leak" memory in pure Java is to keep references to objects you no longer need. There aren't too many ways to do that in an unlimited way - adding to Collections … | |
Re: You can do this in a more compact (but maybe less readable?) way by using an anonymous inner class, eg [CODE]myButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // do whatever } });[/CODE] | |
Re: 20 seconds with the Java API reference would have lead you immediately to the following statement in the doc for contains: [QUOTE]Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).[/QUOTE] In fact it was probably quicker to look … | |
Re: That's the right way to decrement by 10. Just move it to a line after you use it, not before. ie TwoDArray [i][j] = k; k = k-10; ( or k -= 10; - shorter but ewaxctly the same) | |
Re: Are you sure you are talking about Java? Java doesn't have destructors. It has a finalise() method, which is of roughly zero use. If you have finished with an object just ensure there are no remianing references to it. If you have a reference variable that won't go out of … | |
Re: [QUOTE]This is probably the wrong answer...[/QUOTE] I disagree - I think it's a very good answer! | |
Re: "super" means this classes' immediate superclass - in this case it means "Person". Because Employee inherits from Person, any constructor for Employee must first call a constructor from Person to ensure that all the inherited variables etc are correctly initialised. If you don't do this explicitly the compiler puts in … | |
Re: Have a public method in the first class that accepts the object array as a parameter. Pass the first window as a parameter to teh constructor of the second window. When the user clicks OK you can then call the method in the first window to return the data. Edit: … | |
Re: Have you tried catching and displaying any Exceptions that may be thrown? And if you're reading/writing individual bytes, you should use buffered streams or it may just grind to a near halt on a large file | |
Re: The catch on line 24 seems far too general -so if you get an error acessing the data or converting it, or anything else, you always try to create a dircetory and try again. You should check for the exact exception that means you have a missing directory, then follow … | |
Re: You have a block of code in a do { } while(! valid); loop The code will be executed once. If, after that, the boolean [I]valid [/I]is not true this indicates that something was not correct about the execution, so the loop is executed again. The do/while will keep on … | |
Re: This is the Java forum - I suggest you post this question in the databases section instead. | |
Re: Where do you increment ctr after pushing? | |
Re: In your loop you set numberOfDays to the number of days in each month, so each month you overwite the previous values. You should add each month's number of days to the previous value. | |
Re: Have you tried FileNameExtensionFilter("No extension", ""); ? | |
Re: OK, no other answers, so I'll have a go. This is coding on wild side! You use refection to break into private methods that are not part of the public API. Even if you get this to work now, there's no guarantee that it won't break in the very next … | |
Re: [url]http://code.google.com/appengine/docs/java/memcache/[/url] | |
Re: Your deserialised object(s) will contain data with the same values as the original objects - but they will not be the actual same data items as were serialised (eg: you may serialise to a file, quit your app, close the JVM, start a new app in a new JVM and … | |
Re: Maybe you need to special-case the situation where you are adding the first item to a previously empty list (items.length == 0)? | |
Re: Before starting to optimise... do you [B][I]know [/I][/B]that you have a perdormance problem? | |
Re: Use a JLabel with an ImageIcon to display a jpeg. Soemthing like: [CODE] JFrame window = new JFrame("Logo Window"); window.setUndecorated(true); JLabel label = new JLabel(); label.setIcon(new ImageIcon(imageFileName)); window.add(label); window.pack(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2); window.setVisible(true);[/CODE] | |
Re: Don't have time to explain now, but your setVisible on line 5 won't do anything until after your actionPerformed method terminates. It's a threading problem - Google the Swing Event Dispatch Thread. | |
Re: I agree with ~s.o.s~, except why define a CardParser interface? Why not just have a CardParser class that's smart enough to parse any sensible representation? If you onlyhave one class, then why bother with the interface. If you have 2 or mnore pareser classes how will you code the logic … | |
Re: Here are the most common AT commands [url]http://www.modemhelp.net/basicatcommand.shtml[/url] I used javax.comm many years ago, and found it to be not very good quality. Alternatively, under Windows, you can use TAPI (via Com4j or Jacob java/COM bridges), which is a far more modern approach, but a bit tricky and a big … | |
Re: Since nobody more knowlegable has answered, here's my attempt. Swing thinks that it is in charge of what gets painted when because it is responsible for calling the various paint methods. If you go ahead and do painting activities that Swing doesn't know are happenuing then either they won't make … | |
Re: Its a workspace that you have to open, not a project. Projects exist within a workspace, and can only be opened after you have the appropriate workspace. See "switch workspace" in the File menu. | |
Re: What do YOU think is wrong with it? Have you compiled it? Have you executed it? Have you tried executing it with a different value for i1 (eg 0)? | |
Re: You can get the value for the system your Java program is running on from the system properties. It is essential to do this with portable programs, and you should always assume your program is portable, eg, that it might run as an applet or using Webstart. public static String … | |
Re: They are the same. The second version is the universal way of creating a new instance of any class, The first version is a special case for Strings, just for convenience. The same thing applies to creating an array froma literal, as in int[] arr = {1,2,3}; | |
| |
Re: Looks a lot like a Java install/config issue to me. Do you have multiple JRE installations - if so how many, where, and what versions? May be a good idea to clear it all out and just do a clean install of the latest Java | |
Re: This smells like a path problem - it's often a bit trial-and-error to get the getResource parameter to match the actual jar folder hierarchy. This article may help: [url]http://littletutorials.com/2008/03/26/locating-resources-in-java/[/url] | |
Re: vegetables class doesn't have a variable called length. Were you thinking of whatever the getFruits() method returns? Sounds like that may be an array? In which case that's what you should be using instead of calling. | |
Re: I assume you have an int in the range 0 -15, so the clean way to do it is to have an arrray of chars, initilised to '0' ... 'F' and use the int as an index into this array. | |
Re: ^ like Norm says. Plus: When you get the rect values you create a new Rectangle local to the ActionPerformed method, but you don't do anything with it. It will go out of scope when the method terminates, and it will be garbage collected. One thing you could do is … | |
Re: Declare them public, import the package, refer to them by fully-qualified name. | |
Re: Don't you mean deflate? [url]http://en.wikipedia.org/wiki/DEFLATE[/url] | |
Re: If portability across operating systems is important, and you need the power of a full programming language, the Java is the obvious choice. The only reasons for using C++ would be a need to program at a very low level (device drivers etc) or for absolutely massive applications where every … | |
Re: You can use an ObjectOutputStrem / ObjectInputStream via you sockets to send a set of results. If all the calsses & subclasses are serialisable that simply works. If not, extract the data into something that is serialisable and send those. | |
Re: Consider these two methods: int sum(int a, int b) idempotent - every call gives same result void writeToDatabase(String a) not. database gets bigger with every call or String toString() idempotent int getNextPrimeNumber() each call gives a different result | |
The End.