ArrayStoreException for no reason? - java

I am trying to make classes to do the following:
Get a folder, get what folder it contains, and for each folder that is in the main folder - get the files in it and move them into two groups - ones that are mp4, mkv, vlc and avi types and ones that are srt types.
My current code is:
Show.class: http://pastebin.com/vZ7ipFJc
Season.class: http://pastebin.com/tqUJ7S9v
Main.class: http://pastebin.com/LaEvuARW
The stacktrace leads me to many different places:
Exception in thread "main" java.lang.ArrayStoreException
at java.lang.System.arraycopy(Native Method)
at java.util.ArrayList.toArray(Unknown Source)
at Show.<init>(Show.java:47)
at Main.getShows(Main.java:24)
at Main.setupShowsBox(Main.java:70)
at Main.<init>(Main.java:96)
at Main.main(Main.java:54)
(The lines in pastebin are the same as in code) And the problem seems to be where I convert the arraylist into an array, and I dont know what the problem is. What is the problem and how can I fix it?

So here's the line causing the error:
List<Season> seasons;
File[] seasonFile;
this.seasonsFile=seasons.toArray(new File[seasons.size()]);
You're trying to convert a list of Seasons to an array of Files. You can convert a list of Files to an array of Files, or you can convert a list of Seasons to an array of Seasons using toArray().
If you have a way of converting Season objects to File objects you could put that in a toFile() method on your Season object. Then to get your file array:
int idx = 0;
for (season : seasons) {
seasonsFile[idx] = season.toFile();
idx++;
}

You have this line 47 in Show.java:
this.seasonsFile=seasons.toArray(new File[seasons.size()])
seasons is an ArrayList of Season. ArrayList#toArray is not going to be able to squeeze a load of Seasons into an array of Files. Maybe you wanted this.seasonsFile = seasons.getShows;?
Also, you shouldn't have package private variable names following the convention of method names. It's going to confuse everyone.

Related

Is there a way to split up or reduce the size of my string array?

I'm using Xtext to generate a parser for my language. But after the java files are generated, i am getting errors :"The code for the static initializer is exceeding the 65535 bytes limit" in my lexer classes.
I found out it's due to one String Array being 13k lines long.
The code is automatically generated so I have no real control about how that array is used.
I tried moving it into a separate class, but the Array itself is too big for the 65k limit.
package com.intercope.analysis1.parser.antlr.internal;
public class ExternalArrays {
static final String[] DFA28_transitionS = {" {
"\11\76\2\75\2\76\1\75\22\76\1\75\1\10\1\73\1\65\3\76\1\74\1\43\1\44\1\61\1\57\1\45\1\60\1\76\1\46\2\70\1\64\2\70\1\66\1\67\3\70\1\76\1\36\1\6\1\5\1\7\2\76\1\3\1\52\1\16\1\20\1\24\1\31\1\37\1\72\1\34\2\72\1\25\1\23\1\22\1\1\1\14\1\72\1\21\1\27\1\32\1\12\1\63\1\41\3\72\3\76\1\71\1\72\1\76\1\4\1\51\1\15\1\17\1\56\1\30\1\40\1\72\1\33\2\72\1\50\1\53\1\72\1\2\1\13\1\72\1\35\1\26\1\47\1\11\1\62\1\42\3\72\1\54\1\76\1\55\uff82\76",
"\1\103\2\uffff\1\101\1\uffff\1\77\1\102\3\uffff\1\100", ...};
}
Since these are values depending on my lexer grammar I cant generate them using a function.
Any suggestions on how I can fix this is appreciated ^^
Edit: An excerpt from the array:
"\1\u0310\1\uffff\1\u0313\7\uffff\1\u0312\1\uffff\1\u030f\2\uffff\1\u0311",
"\1\u0314",
"\1\u0315",
"\1\u0316",
"\1\u0317",
"\1\u0318",
"\1\u0319",
"\12\104\7\uffff\32\104\4\uffff\1\104\1\uffff\32\104",
"\1\u031b",
"\12\104\7\uffff\32\104\4\uffff\1\104\1\uffff\32\104",
"\12\104\7\uffff\32\104\4\uffff\1\104\1\uffff\32\104",
"\1\u031e",
"\1\u031f",
"\1\u0320",
"\1\u0321",
"\1\u0322",
"\12\104\7\uffff\32\104\4\uffff\1\104\1\uffff\32\104",
"\1\u0324",
"\12\104\7\uffff\32\104\4\uffff\1\u0325\1\uffff\32\104",
"\12\104\7\uffff\32\104\4\uffff\1\104\1\uffff\32\104",
"\1\u0328",
"\1\u032c\1\uffff\1\u032b\12\uffff\1\u0329\2\uffff\1\u032a\1\uffff\1\u032d",
"\1\u032e",
"\1\u032f",
"\1\u0330",
"\1\u0331",
"\1\u0332",
"\1\u0333",
"\1\u0334",
"\1\u0335",
"\1\u0336",

JFlex Scanner ArrayIndexOutOfBoundsException: 769

I am trying to create a Scanner with JFlex. I created my .jflex file and it compiles and everything. The problem is that when I try to prove it, some times it gives me and error of ArrayIndexOutOfBoundsException: 769 in the .java class that JFlex created.
I am using Cup Parser generator too. I don't know if the problem can be related with the part of Cup Analysis, but here is how I called my analyzers.
ScannerLexico lexico = new ScannerLexico(new BufferedReader(new StringReader( jTextPane1.getText())));
ParserSintactico sintaxis = new ParserSintactico(lexico);
I don't know how to fix it. Please help me.
Here are the links to my code:
JFlex File "ScannerFranklin.jflex"
Java Class generated "ScannerLexico.java"
The part where I have the problem in the .java class created by JFlex, in next_token() function (Line 899 in java file).
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
if (zzNext == -1) break zzForAction;
zzState = zzNext;
Thanks.
According to its documentation, JFlex throws ArrayIndexOutOfBounds exceptions whenever it encounters Unicode characters using the %7bit or %8bit/%full encoding options. It recommends to always use the %unicode option instead, which is the default.
You are using the %unicode option, but you're also using %full. Apparently when you have both options, %full takes precedence. So remove %full and the error should go away.

Problems generating '.pas' file with Java2OP and compiling it

I have 2 JAR files coming from an SDK that I have to use.
Generation problem
I succeeded in generating the first .pas file, but Java2OP fails to generate the second .pas I need, with the message
Access violation at address 0042AF4A dans the 'Java2OP.exe' module. Read at address 09D00000
Would this come from a common issue? There's no other hints about what causes the problem in the SDK .jar.
I'm using Java2OP located in C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\converters\java2op, but I had to first use the solutions in Delphi 10.1 Berlin - Java2OP: class or interface expected before generating the 1st file.
Compilation problem
Anyway, I tried to generate a .hpp file from the generated .pas.
I don't know much about Delphi. Does the problem come from the SDK itself, or the generation of the .pas file?
1st issue solved
Java2OP included Androidapi.JNI.Java.Util
and not Androidapi.JNI.JavaUtil. I had to import Androidapi.JNI.JavaUtil myself, though it is present in the /Program Files(x86)/Embarcadero/... folders.
2nd issue
The same 4 compilation errors happen multiple times across the .pas file on parts using the word this.
Do I have to replace every use of this with self?
Errors
E2023 The function require a type of result : Line 4
E2147 The property 'this' doesn't exist in the base class : Line 5
E2029 ',' or ':' awaited but found 'read' identificator : Line 5
E2029 ',' or ':' awaited but found number : Line 5
[JavaSignature('com/hsm/barcode/DecoderConfigValues$SymbologyFlags')]
JDecoderConfigValues_SymbologyFlags = interface(JObject)
['{BCF30FD2-B650-433C-8A4E-8B638A508487}']
function _Getthis$0: JDecoderConfigValues; cdecl;
property this$0: JDecoderConfigValues read _Getthis$0;
end;
[JavaSignature('com/hsm/barcode/ExposureValues$ExposureSettingsMinMax')]
JExposureValues_ExposureSettingsMinMax = interface(JObject)
['{A576F85F-A021-475C-9741-06D92DBC205F}']
function _Getthis$0: JExposureValues; cdecl;
property this$0: JExposureValues read _Getthis$0;
end;

How to call String[][] in R using rjava

I am preparing an R wrapper for a java code that I didn't write myself (and in fact I don't know java). I am trying to use rJava for the first time and I am struggling to get the .jcall right.
Here is an extract of the java code for which I write a wrapper:
public class Model4R{
[...cut...]
public String[][] runModel(String dir, String initFileName, String[] variableNames, int numSims) throws Exception {
[...cut...]
dir and initFileName are character strings for the directory and file name with initial conditions, variable names is a list of character strings that I would write like this in R: c("var1", "var2", "var3", ...) and can be of length from one to five. Finally, numSim is an integer.
Here is my tentative R code for a wrapper function:
runmodel <- function(dir, inFile, varNames, numSim){
hjw <- .jnew("Model4R")
out <- .jcall(hjw, "[[Ljava/lang/String", "runModel", as.character(dir), as.character(inFile), as.vector(varNames), as.integer(numSim))
return(out)
}
The error in R is:
Error in .jcall(hjw, "[[Ljava/lang/String", "runModel", as.character(dir),
: method runModel with signature (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;II)[[Ljava/lang/String not found
I suspect that the JNI type isn't correct for String[][]. Anyhow, any help that could direct me towards a solution would be welcome!
You're missing a semicolon at the end of the JNI for String[][] - it should be "[[Ljava/lang/String;". Also, I think you need to call .jarray instead of as.vector on varNames. The R error is telling you that rJava thinks the class of the third argument is Ljava/lang/String; instead of [Ljava/lang/String;.

Get unresolved imports

I'm writing eclipse plugin that looks for unresolved imports in all source files.
I found that it can be helpful to use IProblem or IMarker objects. Here's code example
public IMarker[] findJavaProblemMarkers(ICompilationUnit cu)
throws CoreException {
IResource javaSourceFile = cu.getUnderlyingResource();
IMarker[] markers =
javaSourceFile.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER,
true, IResource.DEPTH_INFINITE);
}
frome here
I don't know how I can get info from IProblem or IMarker about which import cause the compilation problem (unresolved import).
Any help?
http://help.eclipse.org/indigo/index.jsp?topic=/org.eclipse.jdt.doc.isv/guide/jdt_api_classpath.htm
There are a list of different int values in the IProblem interface representing different errors; if you could get the errorcodes of a file somehow, you could use them. (Example, ImportNotVisible, ImportNotFound, etc.). Just check if the error ID matches one of the error ID's for import failures there.
An IMarker knows the line number and start and stop chars for the java source marked by the IMarker. You can take the substring of the java source string and, if the marker type indicates that it's a problem with the class or import, you can search the project's classpath for a class or package matching (or similar to) that substring.

Categories

Resources