I have a quite strange issue with Java, I'm getting an error on some machines only, I would like to know if there is any way I can avoid that:
This is the line of code concerned:
JSONTokener jsonTokener = new JSONTokener(
new InputStreamReader(is, "UTF-8"));
This is the error I get on some machines
The file *.java could not be compiled. Error raised is : The constructor JSONTokener(InputStreamReader) is undefined
Check the classpath on the machines where this error occurs. This could happen because the library that contains the JSONTokener class is from an older version, where only the JSONTokener(String) is available, and not JSONTokener(Reader).
Related
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.
I'm using jackson-dataformat-csv to read a csv file in, and I'm getting a NoSuchMethodError when trying to parse the mappingIterator with the line
MyRecord record = (MyRecord) it.nextValue();
of this snipped (slightly modified, ex handling removed)
CsvMapper csvMapper = new CsvMapper();
CsvSchema schema = csvMapper.schemaFor(MyRecord.class);
#SuppressWarnings("rawtypes")
MappingIterator<Entry> it = csvMapper.reader(MyRecord.class)
.with(schema).readValues(filename);
List<MyRecord> records = new ArrayList<>();
while (it.hasNextValue()) {
MyRecord record = (MyRecord) it.nextValue();
records.add(record);
}
https://github.com/FasterXML/jackson-dataformat-csv/issues/49
My issue is very close to this one, except I've already tried the solution of making sure jackson-core, jackson-databind, jackson-dataformat-csv, and jackson-annotations are all the same version (2.8). It looks like there is a 2.9 that changes things now, but at my company I don't have access to 2.9. Is there some other package I could have a conflict in?
error:
Exception in thread "main" java.lang.NoSuchMethodError: com.fasterxml.jackson.core.util.BufferRecycler.allocCharBuffer(II)[C
at com.fasterxml.jackson.dataformat.csv.impl.TextBuffer.findBuffer(TextBuffer.java:160)
at com.fasterxml.jackson.dataformat.csv.impl.TextBuffer.emptyAndGetCurrentSegment(TextBuffer.java:404)
at com.fasterxml.jackson.dataformat.csv.impl.CsvDecoder.nextString(CsvDecoder.java:607)
at com.fasterxml.jackson.dataformat.csv.CsvParser._handleNextEntry(CsvParser.java:678)
at com.fasterxml.jackson.dataformat.csv.CsvParser.nextToken(CsvParser.java:523)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:118)
at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:189)
This has been solved, although I'm still not sure about the root cause. I believe the root cause may be specific to my own use case (my company uses it's own in-house systems for local development workspaces as well as dependency management. I ended up creating a new local (and eclipse) workspace and this same code seems to be working fine now.
I have a question regarding calling java class from ColdFusion using Javaloader 1.1.
I attempted to access java class from ColdFusion in a local server, and there was no problem. But when I tried the same thing in office server, I got an error:
"the specified directory
mypath\Javaloader/tmp/AEFACE9B-1C6F-6569-2329 could not be created.
The most Likely cause of this error that mypath \ /
tmp/AEFACE9B-1C6F-6569-2329 already exists on your file system."
And another message
"The error occured in Javaloader.cfc line 269". Javaloader.cfc line
269 is < cfdirectory action="create" directory="#path#" >
what do those error messages mean?
this is my code:
//calling java from coldfusion
<cfscript>
sourcePaths = [expandPath("./src")];
loader = createObject("component", "javaloader.JavaLoader").init(sourceDirectories=sourcePaths);
obj = loader.create("myClass").init();
</cfscript>
I really have no idea. Any solution will be much appreciated. Thank you in advance...
I am using scanner class in java5, and the following code will throw an exception:
Scanner scanner = new Scanner
(new File(args[0]));
int dealId;
while (scanner.hasNextLine()) {
dealId = scanner.nextInt();
System.out.println(dealId);
}
scanner.close();
The stacktrace is:
Exception in thread "main" java.lang.NullPointerException
at java.util.regex.Matcher.toMatchResult(libgcj.so.10)
at java.util.Scanner.myCoreNext(libgcj.so.10)
at java.util.Scanner.myPrepareForNext(libgcj.so.10)
at java.util.Scanner.myNextLine(libgcj.so.10)
at java.util.Scanner.hasNextLine(libgcj.so.10)
Does anybody knows what caused this exception?
The GCJ Home Page suggest it "supports most of the 1.4 libraries plus some 1.5 additions. "
Scanner was added in version 1.5 and I suspect you have hit a piece of functionality GCJ doesn't support. You need to try something different to see what you can get to work.
Is there any reason you are not using OpenJDK/Oracle Java 6 or 7? (Please don't say its for performance reasons ;)
I reproduced the error and found a work around
Here is the code, compiled on x86_64 GNU/Linux, Fedora with Java 1.5.0:
Scanner r = new Scanner(f, "ISO-8859-1");
while(r.hasNext()){
String line = r.nextLine(); //The guts of nextLine(), specifically:
//Matcher.toMatchResult bubbles up a
//nullPointerException
}
The file just contains two ascii words separated by a newline. The runtime Exception only occurs when nextLine processes the last line of the file, whether it has characters or not:
java.lang.NullPointerException
at java.util.regex.Matcher.toMatchResult(libgcj.so.10)
at java.util.Scanner.myCoreNext(libgcj.so.10)
at java.util.Scanner.myPrepareForNext(libgcj.so.10)
at java.util.Scanner.myNextLine(libgcj.so.10)
at java.util.Scanner.nextLine(libgcj.so.10)
at Main.parseFile(Main.java:1449)
at Main.construct(Main.java:1420)
at Main.populateBlogPosts(Main.java:1399)
at Main.main(Main.java:263)
Here is a bug report on this issue: https://bugs.openjdk.java.net/browse/JDK-6178785
Diagnosis
It's a bug in libgcj.so.10, perfectly legitimate ascii input as well as blankstring causes it to puke an NPE on the last line of a file.
Workaround
Since this bug only occurs on the very last line of the file, the hacky workaround is to initially make sure there is at least one newline at the end of the file, then catch and ignore the nullPointerException bubbled up from toMatchResult and exit the loop when that happens.
I'm a Java newbie, but I am an experienced programmer (Assembler, COBOL, C/C++, REXX)
I can't understand why the compiler is giving me the following:
[loading java\lang\Throwable.class(java\lang:Throwable.class)]
src\LU62XnsCvr.java:265: incompatible types
found : java.lang.String
required: java.lang.StringBuffer
Code:
message_data = "LU62XCE0513: Request File I/O Exception =" ;
I've defined message_data as:
static StringBuffer message_data = new StringBuffer();
So why can't I place a simple literal String into the StringBuffer labeled message_data ?
I mean BOTH are of type String .. right ??
No, String and StringBuffer are totally unrelated. Try
message_data.append("LU62XCE0513: Request File I/O Exception =");
While we're at it: note that StringBuffer is a legacy class, best replaced with StringBuilder in new code, except in the unlikely case that you need to share the object across threads. It's source compatible, so just change the name and you're fine.
Both objects may represent a string but they are thechnically not both of type string. You can create a stringbuffer from a string directly via new StringBuffer(message_data).
Just call message_data.toString() when passing the message to the Throwable