Lance Gray

Greenhorn
+ Follow
since Dec 06, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
6
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lance Gray

Jeff Verdegan wrote:

Lance Gray wrote:

Jeff Verdegan wrote:It is not possible to do what you want in the general case, and certainly not if the resource in question is inside a jar.

Does the Clip really require a File? Is there no mehtod/c'tor that takes an InputStream instead? If there is, then simply use getResourceAsStream() instead of getResource(). If not, then you have the following choices:

1. Use some other class or library that does accept an InputStream.

2. Make sure the file in question is always a priori in a known or discoverable location on the file system.

3. Use getResourceAsStream(), read from the jar resource, write a copy out to a temp file, and give that temp file to Clip.


Thanks for the help. I did a workaround on it by using the tips you gave me. I used #2 and did a few tweaks so that the folder is in the same directory as the JAR file.



Note that this is a very brittle approach if you're planning to distribute this software. If it's just for you and at most a handful of other people who you can ensure will install it the same way, it may be good enough.


Yes, I've noticed that. I guess it's okay since only a few people will get it and I'll be able to fix it up in case a problem occurs. Thanks again.
9 years ago

Jeff Verdegan wrote:It is not possible to do what you want in the general case, and certainly not if the resource in question is inside a jar.

Does the Clip really require a File? Is there no mehtod/c'tor that takes an InputStream instead? If there is, then simply use getResourceAsStream() instead of getResource(). If not, then you have the following choices:

1. Use some other class or library that does accept an InputStream.

2. Make sure the file in question is always a priori in a known or discoverable location on the file system.

3. Use getResourceAsStream(), read from the jar resource, write a copy out to a temp file, and give that temp file to Clip.


Thanks for the help. I did a workaround on it by using the tips you gave me. I used #2 and did a few tweaks so that the folder is in the same directory as the JAR file.
9 years ago
I have a program that plays a number of WAV files. I am using getClass().getResource("/sounds/wav") to get the directory where the WAV files are stored and a Clip object to play the sounds. The Clip object needs the directory in the format of "C:/aaaa/bbbb/cccc/sounds/wav/sound0001.wav". I had it working while in the NetBeans IDE but when I run it from a compiled JAR file, it won't work. I investigated it and it seemed that getClass().getResource("/sounds/wav") returned "jar:file:/C:/aaaa/bbbb/cccc/dist/myprog.jar!/sounds/wav" and not the usual "file:/C:/aaaa/bbbb/cccc/sounds/wav" in the IDE. I don't want to change my WAV player since it's already working good. I only need to change the method that obtains the file in the folder.

How do I resolve this? Thanks in advance. If you need more info or code, just post it here and I'll reply with the correct one.
9 years ago
I am having a bit of a problem regarding the mouse. I am using MouseInfo.getPointerInfo().getLocation() to get the mouse pointer's location on the screen and trying to get a JLabel follow the mouse pointer.

When I do it on a new Project with a simple JFrame and the said JLabel, it works as it should. However, when I placed it on my real project, I encountered problems positioning the JLabel. The JLabel moves as the mouse moves but the location is wrong. The attached image explains how I set up my JFrame. The green area is the JFrame that contains all the components of my project. Inside it is the blue JPanel that holds other components. The re box is the JLabel I need to move. The purple are is another JPanel that holds yet other components. The orange ones are a custom JPanel.

I've set it up so that when the mouse enters the orange area, the red JLabel moves towards the cursor's position. Then when the cursor moves while inside the orange JPanel, the JLabel follows along. When the cursor leaves the orange JPanel, it resets back to its position. The problem is, the MouseListener is inside the orange JPanel and I'm controlling the red JLabel from there. When I tested it out, the position of the JLabel is wrong, or rather, is way off the desired position (as MouseInfo.getPointerInfo().getLocation() gets the position of the cursor on the screen).

How should I go about this problem? One solution I can think of is to remove the purple JPanel and simply put the orange ones on the blue JPanel. However, the orange JPanels are placed there on a loop with a set of conditions and parameters, meaning, the orange JPanels are dynamic and can be there or not. Any other possible solutions besides this one?

EDIT: I realized this was placed on a wrong forum. Sorry about that.
9 years ago
Thanks. I changed the code to this one and it worked.

9 years ago
I have a class called Dictionary. Now inside the Dictionary class, there are objects called Word. Each Word object has a method called getWord() that returns a String. Each Word object is placed in an ArrayList called DictionaryEntries. Now my problem is, I need to sort the Word objects inside DictionaryEntries using the string that the method getWord() returns. How do I do this?

I tried this one that I have used before but it's only for integers and not Strings.



Thanks in advance.
9 years ago

Jk Robbins wrote:Remove the classpath environment variable and forget about using it. Doing so will only cause you grief.

Right click the Netbeans project and choose properties. Click the Libraries category and make sure all the required jar files are listed in the compile-time libraries list. If you aren't sure which jar file you need, check your stack trace to determine which class threw the error and then you may have to do a google search to determine what jar file contains that class.


For some reason, removing the CLASSPATH variable did the trick. I didn't imported any new JAR files in the Library. I think it's weird. Before I did the changes, everything worked fine, but after the change it threw this error, even though the Library and CLASSPATH the same for both times. How come? Also, how do I determine which class threw the error on the stack trace? Is it the class listed on the end? Oh, and thanks a bunch.
9 years ago
I've been writing this project of mine in Java for quite some time now. I've repeatedly built and tested my project (I use NetBeans 6.8on Windows 7, by the way) several times before. Then I went and edited something in the project. Then when I tried to run it from there, this java.lang.NoClassDefFoundError popped up all of a sudden. I've looked into the internet and searched how to fix it but nothing seems to work. I've set my CLASSPATH on the Environment Variables but it won't get fixed. How do I fix this?

It's annoying the heck out of me now since I need to pass this project tomorrow and I was sure everything was working fine. Thanks in advance and I hope someone will answer this quickly.
9 years ago
It seems that the mistake was on the Jasper codes itself. I had a friend help me on this and it turned out I missed a few lines of code. Thanks for the help.
9 years ago
No, it still doesn't work. I've even replaced "reps.jasper" with new File("reps.jasper").getAbsolutePath() but it still gives me the same error.
9 years ago

Rob Spoor wrote:Does file reps.jasper exist? The first argument to fillReportToFile is the source file name (or JasperReport object).


Yes, it does. reps.jasper contains the XML code I posted above. Should I not have placed that code there?
9 years ago
So, I'm testing out how JasperReports works. I downloaded iReport so that I can make quick reports, too. I am using CSV files as a data source for my report. The problem is this. Whenever I run the program, it gives me this Exception in thread "main" net.sf.jasperreports.engine.JRException: Error loading object from file : reps.jasper error. How do I fix this?

Here are my codes so far.



And here is my .jasper file generated by iReport.


9 years ago

Riaan Nel wrote:

Jesper de Jong wrote:JasperReports is a well-known Java reporting library, but I've not used it myself, so I can't tell you any details about it.


I can vouch for it. It's pretty powerful, and easy to use once you get the hang of it.

@OP
You can find a guide here; JasperReports Ultimate Guide


Thank you very much for the link, I really appreciate it.

Another question. What should I download in order to put JasperReports on my project? I downloaded the ZIP and JAR files from sourceforge, just in case. When I try to open the contents of the ZIP file, it looks for an ANT build tool. When I open the JAR file, it says it can't open/read the manifest file. Am I doing things wrong?
9 years ago
I've looked around myself and also found JasperReports. However, I can't seem to find a tutorial or a documentation regarding on using it and importing it on my project.
9 years ago
Is there a simple way to create reports in Java?

What I want to do is to get a number of strings in an ArrayList of objects and then put them on a printable report. Also, i want to put values from a comma-separated file to the printable report.
I've found this JavaDoc but, based from what I've understood, it's not possible to design the report using this. (Correct me if I'm wrong)

So basically, I am looking for a simple report producing class/library that I only have to import on my project (no further installations and similar things) or at least a library that requires little time to study/be familiarized with.
9 years ago