[LibGDX][GWT] Error reading file skin.json in HTML [SerializationException] - java

i'm having some problems deploying a libGDX project to HTML. I have a skin.json file to load basic GUI and Fonts. It work perfect on Android and Desktop but in HTML it doesn't. Here is the stacktrace:
Uncaught Error: java.lang.RuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.SerializationException: Error reading file: data/skins/logo_and_font/logo_and_font.json
at f_b.V$b [as jQ] (html-0.js:7370)
at f_b.Y$b [as lQ] (html-0.js:7370)
at f_b.b_b (html-0.js:5252)
at f_b (html-0.js:1161)
at Be (html-0.js:6955)
at Ge (html-0.js:6136)
at di (html-0.js:6583)
at wh.xh [as Oc] (html-0.js:7361)
at HTMLImageElement.eval (html-0.js:5881)
Here is my .json file that im trying to load:
{
"com.badlogic.gdx.graphics.Color":{
"green":{"a":1, "b":0, "g":1, "r":0},
"white":{"a":1, "b":1, "g":1, "r":1},
"red":{"a":1, "b":0, "g":0, "r":1 },
"black":{"a":1, "b":0, "g":0, "r":0}
},
"com.badlogic.gdx.graphics.g2d.BitmapFont":{
"default-font":{
"file":"basic_font.fnt"
}
},
"com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle":{
"default":{
"font":"default-font",
"fontColor":"white"
}
}
}
If i remove the BitmatFont and LabelStyle block code it will load without any errors
"com.badlogic.gdx.graphics.g2d.BitmapFont":{
"default-font":{
"file":"basic_font.fnt"
}
},
"com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle":{
"default":{
"font":"default-font",
"fontColor":"white"
}
}
I have test it in Opera, Google Chrome, Firefox, and Internet Explorer. And the same error. So its not browser related. The game is being serve in a NodeJs server with express, but i also try it with Apache (XAMPP) and same problem, so don't think is server related. I have try with html:superDev and same problem too. I have remove the quotes from the json file and the same problem.
I load the .json file with asset manager here is the code of how i load it. I load it this way, cause im just loading the basic stuff needed to create a loading screen to then load others assets.
this.manager = new AssetManager();
this.assets = new ObjectMap<String, String>();
this.assets.put("logo_and_font_skin", "data/skins/logo_and_font/logo_and_font.json");
this.manager.load(this.assets.get("logo_and_font_skin"), Skin.class);
this.manager.finishLoading();
If i load it directly with Gdx.files.internal("data/skins/logo_and_font/logo_and_font.json"); I get the same error.
In my *.gwt.xml files i have specified the class that are going to be reflected arcording to libGDX Wiki
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.graphics.g2d.BitmapFont"/>
<extend-configuration-property name="gdx.reflect.include" value="com.badlogic.gdx.scenes.scene2d.ui.Label" />
The URI of the *.gwt.xml is the default one, but i have change to others and still get the same error. (Can't post the links cause i don't have enough reputation)
I compile the project with gradlew.bat html:dist it generated some files in /build/dist and those file are the one the i use to serve the game.
I think thats all i have try, maybe a few more thing but don't remember now. I have like 2 days in this or 3 day. It's my fisrt time deploying to a HTML with libGDX. Here is my environment:
IDE: Android Studio 2.2.3
libGDX Version: 1.9.5
Gradle Version: 2.2.3
GWT Version: 2.8.0
JDK: 1.8.0
English is not my main language so if there some typos, sorry about it.

Put your BitmapFont in your AssetManager that is referenced in your .json file.
Use finishLoading on the asset manager.
Get your BitmapFont from AssetManager.
BitmapFont x= manager.get(".....", BitmapFont.class);
Put that font into ObjectMap
ObjectMap<String, Object> font_map = new ObjectMap<String, Object>();
font_map.put("nameOfFont", x);
Use SkinLoader and pass your dependency as parameter.
manager.load(skinPath, Skin.class, new SkinLoader.SkinParameter(skinAtlas, font_map));

#AbhishekAryan yes i try that and fail too. Thanks for the response anyway.
I keep testing with diferents way of loading the BitmapFont and always fail with an error. And i started thinking that maybe it was an error with libGDX, indeed it was, i updated libGDX to 1.9.6-SNAPSHOT and the problem was solve. I loaded the BitmapFont from my uiskin.json perfectly.

Related

Java: I do not Understand the Relative Paths

I've got following maven project structure as also seen in here (ProjectStructure) :
-maws20.algorithm
|-src/main/resources
|-images
|-menuBanner
|-linearSearchMenuBannerUnsorted.png
|-src/main/java
|-linearSearch.menu
|-LinearSearchMenuBanner.java
I am trying to load that .png image inside of the LinearSearchMenuBanner.java-File with the following Line:
#Override
public Image loadBackgroundImage() {
return new Image(LinearSearchMenuBanner.class.
getResource("/images/menuBanner/linearSearchMenuBannerUnsorted.png").toString());
}
Is this not the correct relative path? Because I get the following error:
...
Caused by: java.lang.NullPointerException: Cannot invoke "java.net.URL.toString()" because the return value of "java.lang.Class.getResource(String)" is null
at linearSearch.menu.LinearSearchMenuBanner.loadBackgroundImage(LinearSearchMenuBanner.java:20)
...
(Line 20 is the line shown above)
I thought I understood the relative paths in Java. ^^'
Thank you for any help.
Remove the first back slash /, which actually means absolute path not the relative path.
Try this:
#Override
public Image loadBackgroundImage() {
File resource = new ClassPathResource("images/menuBanner/linearSearchMenuBannerUnsorted.png").getFile();
return new Image(new String(Files.readAllBytes(resource.toPath()));
}
To know more, you can visit this link: spring-classpath-file-access
Thanks for all your help. I don't know what went wrong, but when i create a completly new Workspace after that create all files new and copy the source code to the new files. Then it works fine.
I dont know why...
But thank you very much :)
I guess this is related to your packaging. The image needs to be on the servers file system, the JAR resources will not work!
ClassPathResource
Supports resolution as java.io.File if the class path resource resides in the file system, but not for resources in a JAR. Always supports resolution as URL.
You are in package search.menu and you need to access the file resource in images/menuBanner So you need to load a resource:

new ClassPathResource(“../../images/menuBanner/linearSearchMenuBannerUnsorted.png
“, LinearSearchMenuBanner
.class).getFile();



Hava a look into other options here:
https://www.baeldung.com/spring-classpath-file-access

getting error : java.lang.UnsatisfiedLinkError: Native Library C:\opencv\build\java\x64\opencv_java300.dll

I am running a servlet program to read an image using opencv,
getting error :
java.lang.UnsatisfiedLinkError: Native Library C:\opencv\build\java\x64\opencv_java300.dll already loaded in another classloader . When restarting the IDE it works fine.
I loaded System.loadLibrary ( Core.NATIVE_LIBRARY_NAME ) ; in servlet only ones.
Can anybody suggest a solution for how to unload it. And also anybody know how to read an image from browser using opencv in java.?
It is because the library is not in the system path, it needs to first added to the system path, then load. First extract the OpenCV to C drive something like this c:\opencv\... then use this code below to during initializing, it will automatically load the OpenCV lib in windows environment.
public static void loadOpenCV_Lib() throws Exception {
String model = System.getProperty("sun.arch.data.model");
String libraryPath = "C:/opencv/build/java/x86/";
if(model.equals("64")) {
libraryPath = "C:/opencv/build/java/x64/";
}
System.setProperty("java.library.path", libraryPath);
Field sysPath = ClassLoader.class.getDeclaredField("sys_paths");
sysPath.setAccessible(true);
sysPath.set(null, null);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
And also it will automatically detect the system model and load the lib according to the system model.

How can I run a libGDX application on a non-GUI server environment?

I built a libGDX application that runs well on my PC desktop but when I try to run it on my Ubuntu server, it raises the following error:
"LwjglApplication: Couldn't initialize audio, disabling audio
java.lang.UnsatisfiedLinkError: /tmp/libgdxroot/31ce78a2/liblwjgl64.so: /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/../lib/amd64/libjawt.so: symbol awt_Unlock, version SUNWprivate_1.1 not defined in file libmawt.so with link time reference".
I know this is because my server is running in non-GUI mode. But how can I run my libGDX app in this environment?. I've heard about "libGDX headless backend". But I don't know how to use it.
Thanks in advance.
I've answer my self this question for anyone who's looking for this.
First, added these two libraries in the build.gradle file:
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
compile "org.mockito:mockito-all:1.9.5"
Then, I've started my libGDX as following:
HeadlessNativesLoader.load();
MockGraphics mockGraphics = new MockGraphics();
Gdx.graphics = mockGraphics;
HeadlessNet headlessNet = new HeadlessNet();
Gdx.net = headlessNet;
HeadlessFiles headlessFiles = new HeadlessFiles();
Gdx.files = headlessFiles;
Gdx.gl = mock(GL20.class);
HeadlessApplicationConfiguration config = new HeadlessApplicationConfiguration();
ApplicationListener myGdxGame = EntryPoint.getHeadlessMyGdxGame(config);
and EntryPoint.getHeadlessMyGdxGame return an inherited of HeadlessApplication

How do I load a LWUIT theme file into my Java project?

I am relatively new to Java, so bear with me.
I am completing a tutorial on LWUIT, and just want to load a simple theme, created using the editor. Here is the code in question:
try
{
Container container = c.getContainer();
container.setVisible(true);
Display.init(container);
Display.getInstance().setPureTouch(true);
//Resources r = Resources.open(getClass().getResourceAsStream("/res/Theme.res"));
Resources r = Resources.open("/res/Theme.res");
UIManager.getInstance().setThemeProps(r.getTheme("Simple"));
}
When I use the first (commented out) statement, I get
*** Signal: alarm { "name":"XletException", "domain":"ams", "appId":"com.thomasdge.xlet.hellojamaica.HelloJamaica", "msg":"XletAction['initXlet'] resulted in exception com.aicas.xlet.manager.AMSError: running xlet code caused java exception: initXlet() resulted in exception: java.lang.NullPointerException: <null>.read()I", "data":{ } }
When I use the other, I get
java.io.IOException: /res/Theme.res not found
I have my Theme.res file in /res/Theme. I have also tried it directly in the root, as well as /src. Same results for each.
Any ideas?
If you put the res file in that folder, you will need to go down one level. I recommend you to put the res in the src folder. So, /src/Theme.res. In the code you will only need to write Resources r = Resources.open("/Theme.res");
If resource file placed in res folder, you need to add res folder in project properties. Also you mentioned, the problem even in /src folder, I feel you didn't change the path. Just use Resources.open("/Theme.res") when you use /src folder. Also check the theme name. This should work.

Office 2007 is unable to open files when called through JACOB from a service

I'm using JACOB to do COM calls to PowerPoint and other Office applications from Java. On a particular Windows 7 box I'm getting the following message quite often, but not always:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
From excel I get:
ERROR - Invoke of: Open
Source: Microsoft Office Excel
Description: Microsoft Office Excel cannot access the file 'c:\marchena\marchena10\work\marchena\batch_58288\input\content_1.xlsx'. There are several possible reasons:
? The file name or path does not exist.
? The file is being used by another program.
? The workbook you are trying to save has the same name as a currently open workbook.
The Word error is just:
VariantChangeType failed
The following is what I'm running, the error comes from the last line.
ComThread.InitSTA();
slideApp = new ActiveXComponent("PowerPoint.Application");
Dispatch presentations = slideApp.getProperty("Presentations").toDispatch();
Dispatch presentation = Dispatch.call(presentations, "Open", inputFile.getAbsolutePath(),
MsoTriState.msoTrue.getInteger(), // ReadOnly
MsoTriState.msoFalse.getInteger(), // Untitled The Untitled parameter is used to create a copy of the presentation.
MsoTriState.msoFalse.getInteger() // WithWindow
).toDispatch();
I've tried putting a breakpoint just before doing the Open call and the file is there, and I can actually open it with PowerPoint in the GUI but when I step the exception is thrown.
The annoying thing about this issue is that it seems to happen continuously to begin with, but after poking at it for a while (rerunning the same code), it eventually completes successfully, and after that never reoccurs.
Further research I've found this only happens with to .ppt, .doc and .xls files, not .pptx, .docx and .xlsx. And as far as I can tell it's not file system related (I've swapped out the mechanism that copies the files and tried putting the files on a different file system).
I've just noticed that this only happens when the Java application is running as a service, not when I run catalina.bat start from command line.
I had the same problem (jacob in service not working), and this helpful posting (changing the dcomcnfg) did the trick:
http://bytes.com/topic/c-sharp/answers/819740-c-service-excel-application-workbooks-open-fails-when-called-service#post3466746
Does this work for you?
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class PPT {
private static final String inputFile = "c:\\learning.ppt";
public static void main(String[] args) {
ActiveXComponent slideApp = new ActiveXComponent("PowerPoint.Application");
slideApp.setProperty("Visible", new Variant(true));
ActiveXComponent presentations = slideApp.getPropertyAsComponent("Presentations");
ActiveXComponent presentation = presentations.invokeGetComponent("Open",new Variant(inputFile), new Variant(true));
ComThread.Release();
}
}
Update: If this is working the client and it's just automation that is causing the issues, you can view http://support.microsoft.com/kb/257757 to look at possible issues. There error codes are obviously different, but it may help you troubleshoot all the same.

Categories