This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!

Tony Docherty

Bartender
+ Follow
since Aug 07, 2007
Cows and Likes
Cows
Total received
86
In last 30 days
0
Total given
54
Likes
Total received
509
Received in last 30 days
0
Total given
480
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tony Docherty

Yes I believe you can do this by extending FileView to create your own FileView class that returns the appropriate icon (from the getIcon() method) or return null to use the default icon. You register your FileView object through the setFileView method in JFileChooser.
1 month ago
Just to add more detail to my suggestion, Here's 2 basic ways of solving this written in plain text.

1. Look at each letter in turn and if it's not in my results list add it to the list and then iterate across the rest of the string to count how many times that letter occurs and write down the total number of occurrences.
2. Look at each letter in turn and if it's not in my results list add it to the list with the number 1 next to it. If it is in the list add 1 to the number next to it.
1 month ago
Your code looks like the sort of code you get when you just start writing code without a real plan - it's far more convoluted and complicated than it needs to be. May I suggest you get a pen and paper and write out in plain text the steps you would take to solve the problem yourself and then look to convert that to code.
1 month ago
In what way are you stuck? Please explain exactly what you want to do and what is actually happening.
2 months ago
Not sure that this will solve your problem but it's generally bad practice to perform long running tasks on the EDT, you should use a worker thread to run the task in the background. If your task is also interacting with the GUI (as yours is) you can use a SwingWorker see this tutorial: https://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html.

BTW why are you calling message.split() and then not using the returned array anywhere.
2 months ago

Leonardo Nash wrote:
- Is it bad idea to read data from same InputStream using multiple wrapper Streams (BufferedInputStream, DataInputStream, and another subclass of FilteredInputStream) ? If it is, why ?


If you mean chain wrappers together (ie wrap a FileInputStream in a BufferedInputStream which is wrapped in a DataInputStream) then this is fine but if you mean to wrap one InputStream in 2 or more different wrappers then this is not a good idea. The reason is if you read from one wrapper it will consume and return values from the underlying stream then when you read from another wrapper it will consume and return the next available values from the underlying stream and so the second read will be missing the values already read in via the first stream. Unless you are extremely careful you will have no idea what the data being read in actually means as it will be be starting from some unknown point in the stream.

Leonardo Nash wrote:
- Is it bad idea to call reset, mark methods from base InputStream that passed to wrapper InputStream (BufferedInputStream, ...) ? I think, we should call these methods from only wrapper InputStream.


The reset, mark methods from InputStream don't do anything (they are null implementations) so there is no point in calling them. As to the general principal of calling methods in base classes of wrapped classes I would say it is a dangerous policy if the methods change the state of the object. For example if you called an InputStream subclass that implemented reset() and then called the wrapping classes reset() method, if the wrapping class provides it's own implementation of reset and mark, then the result is unlikely to be resetting of the file position back to the marked point.
3 months ago
The problem with not calling flush() in the client code (assuming the android stuff works the same as standard Java) is the client is unlikely to send the string until the connection is being closed (or the buffer fills up) so the server will just sit there waiting for the message from the client.
3 months ago
Sorry I've never programmed for android so I can't give you a definitive answer to that but I would have thought you would have needed to call flush().
3 months ago
Can you show the client code as well please and does it use flush() as well.
3 months ago
Your problem is on line 42

When will this not evaluate to true?
3 months ago

Dave Tolls wrote:Sequence does not hav a no-args constructor, so cannot be serialized at all.


You can serialize it using the alternate approach I described in my earlier post provided there are getters and setters for the fields you need to serialize (or you are willing to use reflection).
4 months ago
Not sure why you are saving the state of the object but if you are trying to provide persistent storage then I would advise against using Serializable. if, on the other hand, you are implementing transient storage then Serializable is an acceptable approach, you do need a no args constructor though to deserialise an object.
An alternative approach to extending the Sequence class would be to create a wrapper class which implements the readObject and writeObject methods as stated in the API docs for Serializable. The wrapper class could then handle serialization and deserialization of the Sequence object's state through these methods.
4 months ago
Are you asking how to run the given class from the command line or are you asking how to call the given code from another class?
4 months ago
Glad to hear the advice was useful.
4 months ago