Piet Souris

Bartender
+ Follow
since Mar 08, 2009
Merit badge: grant badges
Forum Moderator
Piet Souris currently moderates these forums:
For More
Netherlands
Cows and Likes
Cows
Total received
212
In last 30 days
0
Total given
155
Likes
Total received
1228
Received in last 30 days
6
Total given
194
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

hi Marcos

thanks for your reply! I always found that classpath-thing a complicated matter anf for what I do I do not need to use classpaths. As you say, the IDE does it for you.
But I will read your link with interest and I will try to make a much more complicated program, to see if I will run into the same problems as you had.

For your topic and your struggle for a solution: enjoy a cow!
1 week ago
hi Marcos,

I don't know whether this reply has anything to do with your problem, but maybe it is of some help.
I have this code:

that runs fine from within my IDE (NetBeans). However, if I run the jar from the commandline, I get this error:
Exception in thread "main" java.nio.file.FileSystemNotFoundException
       at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:156)
       at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:142)
       at java.base/java.nio.file.Path.of(Path.java:209)
       at java.base/java.nio.file.Paths.get(Paths.java:98)
       at marcossilvestri.MarcosSilvestri.main(MarcosSilvestri.java:40)


I found a solution for this problem on StackOverflow, and this code runs from the IDE and the jar runs fine from the commandline:

Hope it is of any use.
1 week ago

Ab Burda wrote:This worked!!!
Thank you.


You are welcome!
1 week ago
Before we had Swing with classes like JFrame and JPanel, we had awt with classes like Frame and Panel.  I made a simplified example. because I didnot have the classes that you use.

1 week ago
By the way: a repaint on a Panel calls the update-method, and the update-method calls the paint-method. As you see, you do invoke paint from your update-method.
1 week ago
The problem is that the applet was based on the old Panel, that has a paint-mechanism that is different from a JPanel. So, change your class so that it extends the old Panel instead of JPanel, and you should be fine.
1 week ago

Stephan van Hulst wrote:
Do you mean:


Yes,

Thank you, Stephan and Tim. When I started, I only knew URLs starting with 'https://', so I thought of using 'file://', as we say in Dutch 'not hindered by any relevant knowledge'.
1 week ago
Thanks, Carey.

If I leave out 'localhost/', both with the URL and the URI, I get this error:

But I may be doing something wrong.

Edit: if I do not start with 'file://", then I do indeed not need the localhost. Complicated stuff...
2 weeks ago
Today I tried java's URLConnection, trying to read a local Json-file  and to compare the lot with javascripts fetch(). I came up with

I noticed that new URL is deprecated, and that I should use URI.toURL:

Am I using the URL and the URI in a correct way? Is there a better way?

Thanks!
2 weeks ago
I have never used Object-streams, nor have I ever wanted to use them, since I like my data in a human-readable format.

A very popular dataformat nowadays is JSON. That is not supported directly by Java, but there are a few libraries that can do the job. For instance, using moshi, you could get:

Output:
{
   "characters": [
       {
           "power": 50,
           "type": "Elf",
           "weapons": [
               "bow",
               "sword",
               "dust"
           ]
       },
       {
           "power": 200,
           "type": "Troll",
           "weapons": [
               "bare hands",
               "big axe"
           ]
       },
       {
           "power": 120,
           "type": "Magician",
           "weapons": [
               "spells",
               "invisibility"
           ]
       }
   ]
}
******************************
{
   "characters": [
       {
           "power": 50,
           "type": "Elf",
           "weapons": [
               "bow",
               "sword",
               "dust"
           ]
       },
       {
           "power": 200,
           "type": "Troll",
           "weapons": [
               "bare hands",
               "big axe",
               "pistol"
           ]
       },
       {
           "power": 120,
           "type": "Magician",
           "weapons": [
               "spells",
               "invisibility"
           ]
       }
   ]
}
**********************************
GameCharacters[characters=[GameCharacter[power=50, type=Elf, weapons=[bow, sword, dust]], GameCharacter[power=200, type=Troll, weapons=[bare hands, big axe]], GameCharacter[power=120, type=Magician, weapons=[spells, invisibility]]]]



2 weeks ago
If you have a List<? super C>, you can add only a C or a subclass of C, but nevertheless that list can contain literally any object. See my last example.
2 weeks ago
Congratulations!

And like Anil says, you have been quite some help here on this site, so enjoy another cow.
I was just trying the new switch pattern matching. I made the example a tag longer, and the result is pretty concise, For what it's worth:
3 weeks ago
For a moment I thought that you could use a UnaryOperator<String> with 7, but apparently the 'n'  has to be a Function.
hi Matthew,

your topic was a good exercise for me to get some experience with moshi. I used Carey's classes, but to save on typing I turned them into records (which must be public in moshi, so have to go in a separate file). This is what I got. The mappings that you use are currently beyond me, but I keep them in mind. Thanks for this opportunity and have a cow!

Output:

1 month ago