Error when using xlsx package in write.xlsx - java

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

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

JPivot Display Mondrian Result

I am trying to display the result of a Mondrian query using JPivot. Many examples are showing how to use the tag library for JSP but I need to use the Java API, I looked at the documentation but I cannot understand how to use it to display the results in the table. Here is my code
Query query = connection.parseQuery(mdxQuery);
Result result = connection.execute(query);
result.print(new PrintWriter(System.out,true));
I would like to know if I can use the result object to build the jpivot table.
Thanks in advance!
First of all, using JPivot
is a pretty bad idea.
It was discontinued back in 2008.
There is a good project which is intended to replace the JPivot called Pivot4j. Despite it is currently under development (0.8 -> 0.9 version), Pivot4j can actually do the business.
However, if we're talking about your case:
result.print(new PrintWriter(System.out,true));
This string prints the HTML code with OLAP cube into your System.out.
You can write the HTML code in some output stream (like FileOuputStream), and then display it.
OutputStream out = new FileOutputStream("result.html");
result.print(new PrintWriter(out, true));
//then display this file in a browser
However, if you want to have the same interface as in JPivot, I don't think there is an easy way to do it without .jsp. In these case I strongly recommend you to try Pivot4j.
Good luck!

OpenCV in Java, why can't I use Mat.CvType.CV_8UC1?

If I try to write that code
Mat.CvType.CV_8UC1
I get the error CvType cannot be resolved or is not a field. What am I missing? I think I've added the correct library and DLL in the project properties because everything else seems to be working. I need to find those CV_8UC1 CV_8UC2, etc.
You can try to use CvType.CV_8UC1 insted of Mat.CvType.CV_8UC1

Exception while Skeleton Tracking using openNI on pre-recorded ONI file

I am trying to run the sample openNI Skeleton Tracking application (UserTracker.java application) on a pre-recorded .oni file. I have edited the SamplesConfig.xml file to direct the input from the ONI file and not a Kinect (I don't actually have one). However, I get the following Exception. Can anybody help me here?
org.OpenNI.StatusException: Function was not implemented!
at org.OpenNI.WrapperUtils.throwOnError(WrapperUtils.java:30)
at org.OpenNI.Context.initFromXmlEx(Context.java:371)
at org.OpenNI.Context.createFromXmlFile(Context.java:36)
at UserTracker.<init>(UserTracker.java:149)
at UserTrackerApplication.main(UserTrackerApplication.java:67)
Any help will be appreciated. Thanks!
EDIT: I found a solution here, this has removed the earlier exception that I was getting, but now I get the following!
org.OpenNI.StatusException: This operation is invalid!
Anybody knows why this is happening?
I had a similar problem, I wanted to read data from a .oni file that I generated and I was getting the same issue. Now the problem is solved and maybe you solved it too, but I think it's important to share information to others that might come to this post. I found some clues in others posts by the way.
So here is the solution. The NiUserTracker sample can be used with an .oni file so I checked the code and they do the following:
xn::Player g_Player; //Global variable
// This goes in the main or another function
if (argc > 1)
{
nRetVal = g_Context.Init();
CHECK_RC(nRetVal, "Init");
nRetVal = g_Context.OpenFileRecording(argv[1], g_Player);
if (nRetVal != XN_STATUS_OK)
{
printf("Can't open recording %s: %s\n", argv[1], xnGetStatusString(nRetVal));
return 1;
}
}
This is C++ code, I work with c++. So as you can see they don't init the kinect via XML file if they want to open a recorded .oni file, they just init it via Init() method and then open a file with openFileRecording method.
If you want to open a .oni file there's no need to modify your XML, this way you can do an application that allows you to chose if you want to use a .oni or the kinect.
I hope this helps someone.
cheers.

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