I'm trying to add my java project in android studio. I got many references & added my Project in Android studio.
Now i am unable to add the assets to my projects. So please help me to solve it
Thanks in Advance
Structure
CODE
this.trayIcon = new TrayIcon(ImageIO.read(this.getClass().getResourceAsStream("icon.png")));
this.trayIcon.setImageAutoSize(true);
this.trayIcon.setToolTip("Remot Server");
this.trayIcon.setPopupMenu(menu);
SystemTray.getSystemTray().add(this.trayIcon);
Error
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1348)
If you refresh your project in the gradle view (the blue arrow) and AS mark it as a resource folder you should be covered. The other thing is the path: Your path should start with a slash /
when using Class.getResource()
because your image is in the root of the resource folder.
See the acccepted answer here: Classpath resource within jar
You resource
directory is in a non-Android Studio standard location. My guess is that you haven't altered your Gradle file to try to include that directory.
Best would be to move the image assets into the standard location, so that the apk packaging routines know what to put where. While its a pain for existing projects the process is straight forward:
Alternatively
You could try to add your resources from your Java project in your build.gradle (app):
android {
....
sourceSets {
main {
// default is resources.srcDirs = ['src']
resources.srcDirs = ['src/main/java']
}
}
}
But I haven't tried it with images.
More details here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Project-Structure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With