How do I change the default application icon in Java?
I tried the above code using Netbeans 7.0 but I'm not sure where the resources directory needs to be? If I use the one Netbeans has under files listing. It keeps giving me this error. Also, is the code correct?
Uncaught error fetching image:
java.lang.NullPointerException
at sun.awt.image.URLImageSource.getConnection(URLImageSource.java:115)
at sun.awt.image.URLImageSource.getDecoder(URLImageSource.java:125)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169)
using this code:
URL url;
url = ClassLoader.getSystemResource("/com/pbuddie/resources/Server.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
clientUI.setIconImage(img);
Related
I'm trying to learn OpenCV 3.2.0 with Java and I am having trouble loading in a video file into the program. I work on Eclipse in Windows 10. This is a snippet from the code:
Mat frame = new Mat();
Mat frameHSV = new Mat();
VideoCapture vcap = new VideoCapture("C:\\Users\\UserName\\Downloads\\video.mov");
while(vcap.read(frame))
{
frameHSV = ColorBase.BGRToHSV(frame);
displayWindow.updateFrame(frameHSV);
}
When I launch this program, I only get a white window with nothing in it. I think this has something to do with this being on windows, as I tried it out on a Linux computer and it worked as intended. This means the path points to the correct location and that the code actually works.
Is this an issue with OpenCV and Paths on windows? I get no complile errors, only a white window. How is this fixed?
I managed to solve it by following another thread on this site that I didn't find before:
OpenCV Java binds VideoCapture from file failing silently
I followed the second answer on this thread and it worked perfectly after that.
Its either a video codec, or permission issue, can you move the file to other drive like: D:\\video.mov and try?
I have integrated Image magick with a Java WebApp and have deployed it on Azure App Service. On azure , I am getting 0kb as output image for a image while the same image gets converted fine on my local machine.
I am using im4java for integration with Image Magick.
Below is the code:
public void compressImage(String imageSource, String destinationPath) throws IOException, InterruptedException,
IM4JavaException {
ConvertCmd cmd = getCommand();
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.strip();
op.interlace();
op.addRawArgs(compressionRawArguments);
op.gaussianBlur(compressionGaussianBlur);
op.quality(compressedImageQuality);
op.addImage(imageSource); // source file
op.addImage(destinationPath); // destination file
// execute the operation
cmd.run(op);
}
Both imageSource and destination are temp files created using java. I have checked that imageSource file has correct size but after running this code, the destination file is always 0 Kb.
Please advise what could I be doing wrong?
Answering my own question so that It might be helpful for fellow developers who might face this problem.
Azure App Service normally has Windows Server VMs. You can check the OS of your server in web container logs.
Image Magick for windows does not allow conversion of remote http
image urls while for Unix System, it allows so. My Local machine is
MAC So it was working correctly on my local system.
2 Solutions to this problem that I found:
Either you use a linux VM on Azure
In your application, download the image URL to a temp file and
supply the absolute path of that temp file to image magick for
conversion.
I have tried both and are both working.
I have an app that runs fine when I am not attempting to use it as a web start app, but when I convert it to one in Netbeans, it goes belly up. The console is showing a null pointer exception when trying to get a resource that is located in a dependent library. The line of code itself grabs a .png file in that library file and uses it for the window icon. The lines of code that kill it is:
java.net.URL url = ClassLoader.getSystemResource("/com/my/icon/someimage.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url); // fails with null pointer exception
If I am not trying to do this as a web start app then I have zero issues. It runs perfectly. Web start = failboat. The code is signed, if that makes any difference. The library file that is being used is one large jar that contains 3 library files I created plus 4 others that are needed which I did not code myself. Do I need to sign the library file as well? Is this possibly an issue in and of itself?
EDIT:
If I take out those lines of code, the web app runs without any issues.
Here is the error:
Exception in thread "AWT-EventQueue-2" java.lang.NullPointerException
at sun.net.util.URLUtil.getConnectPermission(Unknown Source)
at sun.awt.SunToolkit.checkPermissions(Unknown Source)
at sun.awt.SunToolkit.createImage(Unknown Source)
at DDSC.initComponents(DDSC.java:265)
at DDSC.<init>(DDSC.java:103)
Try using getClassLoader().getResource() with just the filename.
Full path isn't required and getClassLoader() handles the magic via WebStart & also locally:
String filename = "someimage.png";
Image resultImg = null;
URL url = getClassLoader().getResource(filename);
if (url != null)
resultImg = Toolkit.getDefaultToolkit().getImage(url);
I got some errors in my app. The app is using applet for accessing local file system.
converting file, for example.
First: Using relative path.
I can place project folder wherever I need and the application still working properly. However, when I placed it on the tomcat server directory, it cannot find the files' path.
Run with browser: file:///C:/report-param/index.html, ok
Run with browser: localhost:8080/report-param/index.html, error
Second: Using absolute path.
The application working well in both browser and tomcat server.
Run with browser: file:///C:/report-param/index.html, ok
Run with browser: localhost:8080/report-param/index.html, ok
Here is my sample code:
File jrxmlPath = new File("reports//people-report-withparam-multi.jrxml");
File pdfPath = new File("reports//people-report-withparam-multi.pdf");
String sourceJrxml = jrxmlPath.getPath();
String destPdf = pdfPath.getPath();
JasperReport jasperReport = JasperCompileManager.compileReport(sourceJrxml);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, paramMap,
getPostgreSQLDataSource(driverUrl, username, password));
JasperExportManager.exportReportToPdfFile(jasperPrint,destPdf);
What is the matter on here? Any ideas?
How can I fix the error above? Please help...
Note: if you don't understand, feel free to ask me...
I have the following line in my Java app, and it's causing the following error message :
WebBrowser webBrowser=new WebBrowser();
org.jdesktop.jdic.init.JdicInitException: java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at org.jdesktop.jdic.init.JdicManager.initBrowserNative(Unknown Source)
at org.jdesktop.jdic.browser.WebBrowser.<clinit>(Unknown Source)
The app still works, but I wonder if there is a way to correct the error ?
There's a problem initializing jdic's native browser but it isn't obvious what it is.
Does passing a URL to the constructor help?
URL url = new URL("http://www.stackoverflow.com");
WebBrowser webBrowser = new WebBrowser();
One more thing to check - do you have a default browser? If so, when you double click on an html file in a file manager does the browser window open? If this doesn't work then perhaps jdic is complaining about your default browser path.