LibGDX AssetManager: Asset not loaded only on Android - java

When I try to load a file into the asset manager, LibGDX does not seem to pick it up. However, it works perfect on Windows!
I debugged the finishloading() method and It claims the parameter toLoad = 1 but it does not load.
On windows it would say loaded = 1 in the debugging screen.
Code sample:
ParticleEffectLoader.ParticleEffectLoadParameter loadParam = new ParticleEffectLoader.ParticleEffectLoadParameter(particleSystem.getBatches());
ParticleEffectLoader loader = new ParticleEffectLoader(new InternalFileHandleResolver());
Assets.instance.assetManager.setLoader(ParticleEffect.class, loader);
Assets.instance.assetManager.load("bb.pfx", ParticleEffect.class, loadParam);
Assets.instance.assetManager.finishLoading();
effect1=Assets.instance.assetManager.get("bb.pfx",ParticleEffect.class).copy();
The last line fails with a AssetNotLoaded on Android. Filenames are case sensitive, so that is not the error.
com.badlogic.gdx.utils.GdxRuntimeException: Asset not loaded: bb.pfx
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:144)
at bvo.games.colorspace.settings.Assets$AssetBillboard.<init>(Assets.java:109)
Does anyone know a solution to this?

My Asset class was static, on Android this does give unexpected results, as Xoppa pointed out in his comment. Problem solved. :)

Related

Can't import model from MPS file to IloCplex - IBM ILOG CPLEX - Java - Intellij

I'm currently developing a project in java using the Ilog Cplex libraries, I'm using the Intellij-Idea IDE.
I'm having troubles importing a model from MPS file, this is the piece of code that gives me problems
IloCplex iloCplexInstance = new IloCplex();
iloCplexInstance.importModel(fileName);
It fires this exception:
ilog.cplex.CpxException: CPLEX Error 1423: Could not open file 'models\20_70_45_05_100.mps' for reading.
at ilog.cplex.CplexI.CALL(CplexI.java:5204)
at ilog.cplex.CplexI._readModel(CplexI.java:5584)
at ilog.cplex.CplexI.importModel(CplexI.java:1032)
at ilog.cplex.IloCplex.importModel(IloCplex.java:902)
at heuristics.ziround.LPUtils.fromMPS(LPUtils.java:34)
at heuristics.test.LPUtilsTestCompile.main(LPUtilsTestCompile.java:13)
I tried running it in unit tests using junit4, junit.runners.Parameterized, and in a simple class from its main method. Same result in each case. I've also tried to set the full path to the file and it gives the same result.
I know that the file I used is ok, I'm able to read it using the cplex terminal commands, I also tried other files.
The code that uses the Ilog's libraries can compile, I'm not sure if it can run though since I'm not able to import a model I can't try to solve one.
I'm using windows, launching the IDE as admin sorts no effects, and the file is not blocked from reading (nor writing).
I'm following the documentation from IBM:
https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/refjavacplex/html/ilog/cplex/IloCplex.html#importModel(java.lang.String)
In the official support pages, I found this about the error: http://www-eio.upc.es/lceio/manuals/cplex-11/html/refcallablelibrary/html/macros/CPXERR_FAIL_OPEN_READ.html
But I can't find anything useful.
Also, the IBM forum is currently closed and no one seems to have had this kind of problem :(
Does anyone know what could be the trouble? What can I do? Do you know of any other alternative?
Thanks to anyone that will stop by!!
The exception message says:
ilog.cplex.CpxException: CPLEX Error 1423: Could not open file
'models\20_70_45_05_100.mps' for reading.
Try using an absolute path instead, like c:\path\to\your\models\20_70_45_05_100.mps.
You can also add code to your program to make sure the path exists. Something like:
import java.nio.file.Files;
...
IloCplex iloCplexInstance = new IloCplex();
if (!Files.exists(fileName))
throw new AssertionError("path does not exist: " + fileName);
iloCplexInstance.importModel(fileName);
Following #rkersh answer i did this:
String modelsPath = "absolute\\folder\\path";
Collection<Object[]> models = new ArrayList<>();
File folder = new File(modelsPath);
for (final File fileEntry : Objects.requireNonNull(folder.listFiles())) {
if (fileEntry.isFile())
models.add(new String[]{fileEntry.getAbsolutePath()});
}
return models;
This makes sure that the absolute path is correct and now iloCplexInstance.importModel(fileName); accepts it fine

Tomcat webclassloader fails to find a class

In a Tomcat 7 I have a pretty standar jar file on WEB-INF/lib. Inside this jar I have this class called Parser, and next to it (on the same dir) I have another one called AutomaticLocalLoader. Compilation gives no problem at all. In run time the AutomaticLoader class is found, and when It needs the Parser class, I get a NoClassDefFoundError
The Parser and AutomaticLoader class have been working without this problem for 15 years!! in many diferent vers of java and tomact; and now out of the blue, I am getting this NoClassDefFoundError, only for the Parser class. I already put a copy on a directory inside the WEB-INF/classes path and still got the same error. I already created my own ClassLoader to see if I get some error loading the class from the WEB-INF/classes directory by myself, but I can load it without problems.
log.info("Leer " + aFlInstructions[i].getAbsolutePath());
LoaderTest A = new LoaderTest();
A.test("com.hds.resolve.model.aguila.AutomaticLocalLoader");
LoaderTest B = new LoaderTest();
B.test("com.hds.resolve.model.aguila.Parser");
if(!bOverrideInputDir)
Psr = new Parser(aFlInstructions[i]);
else
Psr = new Parser(aFlInstructions[i], new String[] { StrLocalDirectory } );
The LoaderTest class, try to create the Class Object for the given name using Class.forName. If NoClassDefFoundError, then try to load the class using my own classloader and then create the class.
For the AutomaticLoader, it succed at the first try. For the Parser class if fails, then successfully load it with the custom classloader. Of course when the code reach the "new Parser" part, the old webclassloader still fails and throws the NoClassDefFoundError.
Both Parser and AutomaticLocalLoader belong to the same package and are stored on the same jar inside WEB-LIB.
Funny enough, the error does always happen on production... but never in my machine. I do not use customs classloaders except for doing this debug. Also, trying an old version of the software seems to fix the error. No idea why.
I think I can hack a solution messing with the tomcat's webclassloader, but I really would prefer to understand what is going wrong with this code.

OpenCV 3.0.0 FaceDetect Sample fails

I am trying to get OpenCV running i am using the following
sample code
I get the following Error line displayed:
OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp, line 1580
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp:1580: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
]
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:176)
at org.maxbit.opencv.samples.DetectFaceDemo.run(SampleB.java:29)
at org.maxbit.opencv.samples.SampleB.main(SampleB.java:51)
Can any body tell me what that error means or how to debug this?
I also faced the problem. The problem is in the .getPath() return an absolute path of the format.
Eg: "/C:/Users/projects/FaceDetection/bin/com/face/detection/haarcascade_frontalface_alt.xml".
So change the code like this.
CascadeClassifier faceDecetor = new CascadeClassifier(FaceDetection.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
This happens usually for two reasons.
Cascade classifier file lbpcascade_frontalface.xml not present at specified path.
Cascade classifier file is corrupted.
To get an error message instead of exception during runtime, try code sample as below. The CascadeClassifier constructor is silent, if it cannot load the cascade classifier XML. The onus is on the developer to call the empty() method and check if classifier is loaded correctly
CascadeClassifier cascade = new CascadeClassifier( CASCADE_CLASSIFIER_PATH );
if ( cascade.empty() ) {
//handler error here
}
Exception you got is from OpenCV native code assertion here.
I ran into this same error running on a Windows box. This sample runs on linux but not Windows.
The problem is in the .getPath() call after getResource() for both the xml file and the image.
The problem is that the URL.getPath() and the URL.getFile() both return an absolute path of the format "/c:/...".
The OpenCV routines choke on this it must be "c:/..." (no leading '/'). This seems like a bug in the early part of version 3.0.0?
I hope this helps, OpenCV for Java seems like a great tool ... but it is a bit frustrating when the examples don't work.
There is a problem with the latest openCV it doesn't work when you have spaces in your path so do this:
String s =CameraPanel.class.getResource("lbpcascade_frontalface.xml").getPath().substring(1);
String[] split = s.split("%20");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < split.length-1; i++) {
stringBuilder.append(split[i]+" ");
}
stringBuilder.append(split[split.length-1]);
faceDetector = new CascadeClassifier(stringBuilder.toString());
I ran into the same issue: On windows, OpenCV chokes on both the prepended '\' and any whitespace in the path, as both Imad and Aung have noted. My solution is a bit shorter than Imad's:
Change this:
CascadeClassifier faceDecetor = new CascadeClassifier(
getClass().class.getResource("haarcascade_frontalface_alt.xml").getPath());
To this:
CascadeClassifier faceDecetor = new CascadeClassifier(
getClass().class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1).replaceAll("%20", " "));
For me the simplest solution was:
private void checkboxSelection(String classifierPath) {
// load the classifier(s)
faceCascade.load(classifierPath);
// Did it work?
if (faceCascade.empty()) {
// Try the full path
String resource = getClass().getResource(classifierPath).getPath();
// Discard leading / if present.
if ( resource.startsWith("/")) {
resource = resource.substring(1);
}
faceCascade.load(resource);
}
// now the video capture can start
cameraButton.setDisable(false);
}
I am using openCv 3.4.1
I think there's a bug in CascadeClassifier initializer.
In order to get rid of this error, I must call "load" once again. Hope this solution could help.
cascadeClassifier = new CascadeClassifier(mCascadeFile.getAbsolutePath());
cascadeClassifier.load(mCascadeFile.getAbsolutePath());
I faced problem on Mac (OSX) Java.
CameraFrame.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1)
returned "Users/username/Desktop/JavaProjects/Camera/bin/haarcascade_frontalface_alt.xml".
whereas path should start with "/" therefore I appended "/".
face = new CascadeClassifier("/" +
CameraFrame.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
It works OK now :)
I faced the same problem as well. It is just because the path you gave for 'haarcascade_frontalface_alt2.xml' might be incorrect of not proper. just copy the full path from file explorer and paste it. This solution works for me.
face_cascade = cv2.CascadeClassifier('C:/Users/xyz/FaceDetect/faceId/OpenCV-Python-Series-master/src/cascades/data/haarcascade_frontalface_alt2.xml')

Error when using xlsx package in write.xlsx

I am trying to save a file using write.xslx (when saving with write.csv some row got shift in more columns so I am trying to save the file as xlsx directly).
If I type this command:
write.xlsx (old.data, file ="Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
or
write.xlsx (old.data, "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
I get this error:
Error in .jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook") :
Java Exception <no description because toString() failed>.jnew("org/apache/poi/xssf/usermodel/XSSFWorkbook")<S4 object of class "jobjRef">
Can anyone help me sort it out?
I don't think that this question can easily be answered. Is <working_directory>/Documents writeable to you? Can you create the file
write.xlsx ( data.frame( a = 1:10, row.names = letters[ 1:10 ] ), "Documents/new.xlsx", sheetName="Sheet1",col.names=TRUE, row.names=TRUE, append=FALSE)
If this works, but with old.data it doesn't you have to provide a reproducible example.
However, I experienced every here and again weird problems with the xlsx package. From my experience XLConnect is much more robust and bug-free:
library("XLConnect")
writeWorksheetToFile( "Documents/newxlsx", old.data, "Sheet1", header=TRUE, rownames = "rownames.header" )
write_xlsx() from the writexl package works great for me and is way faster! It also works fine with tibbles and does not have the annoying errors or resctrictions from the xlsxpackage. It is also completely written in C so no Java, Perl or Rtools are required.
For more info see https://ropensci.org/technotes/2017/09/08/writexl-release/
I just had this same problem. I think there might be a bug with openXL but I love working with it. So I open and close R and then change the wd, saved the file exactly where the wd was and then I run the exact same code again. It worked.
Today I had that problem after deployment.
At this moment I didn't need to change package and stick to xlsx
I updated dplyr, xlsx, and the one that did the trick was updating rjava.
Since it was a conflict with java and xlsx calls it, I gave it a shot.
Hope this work for you too

Problem with ImageTools plugin in Grails

i have a grails project with an Image Domain Class and Controller.
I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded.
My Image-Domain-Class:
class Image {
byte[] data
//String name
byte[] thumbnail
static constraints = {
//name()
data()
}
}
The "safe"-action in my Controller:
def save = {
def imageInstance = new Image(params)
def imageTool = new ImageTool()
imageTool.load(imageInstance.data)
imageTool.thumbnail(320)
imageInstance.thumbnail = imageTool.getBytes("JPEG") //Here is my problem!
if(!imageInstance.hasErrors() && imageInstance.save()) {
flash.message = "Image ${imageInstance.id} created"
redirect(action:show,id:imageInstance.id)
}
else {
render(view:'create',model:[imageInstance:imageInstance])
}
}
When I start my Grails-application and uploading an image I'm getting the following error-message:
Error 200: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Servlet: grails
URI: /grailsproject/grails/image/save.dispatch
Exception Message: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Caused by: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"}
Class: GrailsAuthenticationProcessingFilter
At Line: [57]
It says that the Method getBytes() is missing but the method is still available. My IDE intelliJ also recognizes no errors.
So what can I do? Could someone help me please?
Sorry for my bad english. If you are german, please look at http://support-network.info/board/problem-mit-imagetools-getbytes-t3008.html .
I use Grails 1.0.4.
I could fix this error message. I just copied the getBytes() method from the git Repository of Ricardo (the plugin developer) and replaced the old one with the new one. Now everything works! I don't know where the bug was but i'm happy that i solved it.
Thank you both very much!
Looks like that method is a fairly new addition to the class (3/6/2009). If you have verified that that method is in the ./plugins/imagetools/src/groovy/ImageTool.groovy file I'd recommend running:
grails clean
If you had been using this plugin prior it might be a cache problem.
The reply that you received from John sounds about right - if you have installed the new plugin and can see the code, but keep getting this error only outside IntelliJ, you should try cleaning your grails cache - it's very possible that an older copy of the plugin is precompiled on the cache.
Are you using Grails 1.1? I haven't yet tested it with the latest grails, but I understand it keeps the plugins not under the project but in a separate directory. Do let me know and I'll try it out.
I don't know what the plugin is really giving you over using JAI directly, IMHO it isn't doing much.
I use ImageMagick out of process for my image conversion and the results are superior to what can be done with JAI from what I have seen. Of course if your doing as much traffic as Amazon running out of process is not an option, however if you need to get to revenue as quickly as possible then you might want to consider what I've done.
I use apache-commons-exec to have a nice interface around handling opening an external process and reading data from std in and out. The only thing I'm using JAI for is to read the sizes of images.
try this one http://support-network.info/board/gel%C3%B6st-problem-mit-imagetools-getbytes-t3008.html

Categories