I'm programming a mod.
Here's the code:
package net.minecraft.client.gui;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.audio.SoundHandler;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
public class GuiButton extends Gui {
public static final ResourceLocation buttonTextures = new ResourceLocation("textures/gui/widgets.png");
As you can see, there's the variable buttonTextures and its resource location is "textures/gui/widgets.png". And I also have a second one and what I want to do is to change the buttonTextures with this second Java file when I execute it.
I just need to change the resource location of buttonTextures to my own path, but by an other Java file. Maybe it can be done by re-writing the code with the second script, I really have no clue.
What I'm making:
A PAYDAY 2 Mod for Minecraft. And of course, I'm starting with the menu. So I have two main menus. To switch to my menu, there's a button which you have to press. When you do that, it changes its texture. But the problem is, that it can't change the button textures to textures/gui/PAYDAY2widgets.png, because the variable is final.
As you can see, the first file is called GuiButton.
I made a copy of that file, called it GuiPAYDAY2Button.java, and set the path to my path to the texture (textures/gui/PAYDAY2widgets.png).
Now if I add that to the | (I changed the variables from GuiButton to GuiPAYDAY2Button, but then the game crashes after switching to the PAYDAY2 menu) | GuiPAYDAY2MainMenu.java file (the copy of the GuiMainMenu.javafile).
I also changed GuiButton to GuiPAYDAY2Button(in the GuiPAYDAY2MainMenu.java file), so it's directed to that file.
As I was talking about the crashing, this is the crash-report:
---- Minecraft Crash Report ---- // I feel sad now :(
Time: 8.4.15 21:58 Description: Rendering screen
java.lang.ClassCastException: net.minecraft.client.gui.GuiPAYDAY2Button cannot be cast to net.minecraft.client.gui.GuiButton
at net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:99)
at net.minecraft.client.gui.GuiPAYDAY2MainMenu.drawScreen(GuiPAYDAY2MainMenu.java:453)
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1167)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1127)
at net.minecraft.client.Minecraft.run(Minecraft.java:410)
at net.minecraft.client.main.Main.main(Main.java:114)
at Start.main(Start.java:11)
A detailed walkthrough of the error, its code path and all known details is as follows:
-- Head --
Stacktrace:
at net.minecraft.client.gui.GuiScreen.drawScreen(GuiScreen.java:99)
at net.minecraft.client.gui.GuiPAYDAY2MainMenu.drawScreen(GuiPAYDAY2MainMenu.java:453)
-- Screen render details --
Details:
Screen name: net.minecraft.client.gui.GuiPAYDAY2MainMenu
Mouse location: Scaled: (202, 11). Absolute: (405, 456)
Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2
Stacktrace:
at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1167)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1127)
at net.minecraft.client.Minecraft.run(Minecraft.java:410)
at net.minecraft.client.main.Main.main(Main.java:114)
at Start.main(Start.java:11)
-- System Details --
Details:
Minecraft Version: 1.8
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.8.0_31, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 707532608 bytes (674 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
Launched Version: mcp
LWJGL: 2.9.1
OpenGL: GeForce GTX 460 v2/PCIe/SSE2 GL version 4.5.0 NVIDIA 347.25, NVIDIA Corporation
GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported.
Using VBOs: No
Is Modded: Very likely; Jar signature invalidated
Type: Client (map_client.txt)
Resource Packs: []
Current Language: English (US)
Profiler Position: N/A (disabled)
UPDATE
I made a video some hours ago and it's a showcase to this mod. Maybe you'll understand what I want..: https://www.youtube.com/watch?v=ocHT7LdNBYY
Ok, I made the extending script look like this:
package net.minecraft.client.gui;
import net.minecraft.util.ResourceLocation;
public class GuiButtonTexureChange extends GuiButton {
public static ResourceLocation buttonTextures = new ResourceLocation("textures/gui/PAYDAY2widgets.png");
// Now this part is needed to be here (otherwise it throws errors):
public GuiButtonTexureChange(int buttonId, int x, int y, int widthIn, int heightIn, String buttonText) {
super(buttonId, x, y, widthIn, heightIn, buttonText); // TODO Auto-generated constructor stub
}
}
If you cannot modify some Java code (for instance it is part of a library), you can still overwrite any Java class you like.
Create another source folder (speaking in terms of Eclipse here), and inside that the exact package and file as the class you want to edit. In your case it should be package net.minecraft.client.gui and file GuiButton.java.
Now, if your own file comes first in classpath, you have successfully overwritten a class. All the other code of the library still works as it used to.
To ensure that your own code comes first in classpath when working with Eclipse:
Project properties -> Java Build Path -> Order and Export
It is probably wise to copy the existing code (of GuiButton) into your own file to have the same starting point, and then do your modifications on the code.
Depending on your security manager settings, you could change the path string at runtime via reflection.
Example :
static void setFinalStatic(final Field field, final Object instance, final Object newValue) throws Exception {
field.setAccessible(true);
final Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL & ~Modifier.PRIVATE);
field.set(instance, newValue);
}
public final static void main(String[] args) throws Exception {
String path = "initialPath";
final char[] after = "sneakyPath".toCharArray();
setFinalStatic(path.getClass().getDeclaredField("value"), path, after);
setFinalStatic(path.getClass().getDeclaredField("offset"), path, 0);
setFinalStatic(path.getClass().getDeclaredField("count"), path, after.length);
System.out.println(path);
}
Related
Initial situation
I've made a little test for my project today - The goal: Implement .jar files into a C# project as a .dll. My current .java / .jar file looks like the following.
package ws;
public class Adding
{
public int Add(int a, int b)
{
return a + b;
}
}
I successfully converted the above into a .dll with IKVM (Version: 7.5.0.2).
I now want to reference this .dll in my C# project and call the Add(int a, int b) method. I already added the reference like so:
Anyways I am not able to call the method, because the compiler can't find the .dll reference..
using Adding; // <= Compiler Error CS0246 (Can't find the reference)
Console.WriteLine(Add(1, 2));
Does anybody know how I could achieve this? I highly appreciate any kind of help, cheers!
Edit 1: Decompiling
I've decompiled the .dll, as demanded in the comments, with ILSpy (Version: ILSpy 7.2), which results into the following output.
// C:\Users\maikh\Desktop\Adding.dll
// Adding, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Global type: <Module>
// Architecture: AnyCPU (64-bit preferred)
// Runtime: v4.0.30319
// Hash algorithm: SHA1
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using IKVM.Attributes;
[assembly: Debuggable(true, false)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: SourceFile(null)]
[module: JavaModule(Jars = new string[] { "Adding.jar" })]
[module: PackageList(new string[] { })]
I've also found some references, while decompiling the .dll. I don't know if this is important to mention, but I'll provide it anyways.
// Detected TargetFramework-Id: .NETFramework,Version=v4.0
// Detected RuntimePack: Microsoft.NETCore.App
// Referenced assemblies (in metadata order):
// IKVM.Runtime, Version=7.5.0.2, Culture=neutral, PublicKeyToken=00d957d768bec828
// Assembly reference loading information:
// There were some problems during assembly reference load, see below for more information!
// Error: Could not find reference: IKVM.Runtime, Version=7.5.0.2, Culture=neutral, PublicKeyToken=00d957d768bec828
// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly reference loading information:
// Info: Success - Found in Assembly List
// Assembly load log including transitive references:
// IKVM.Runtime, Version=7.5.0.2, Culture=neutral, PublicKeyToken=00d957d768bec828
// Error: Could not find reference: IKVM.Runtime, Version=7.5.0.2, Culture=neutral, PublicKeyToken=00d957d768bec828
// mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Info: Success - Found in Assembly List
Edit 2: Decompiling V2
I've managed to add the missing reference IKVM.Runtime. Nevertheless I can't find any informations about the namespace, class or method.
First of all, you are using a class as a namespace, and that is probably not correct. Your method call should probably look something like this:
var adder = new Adding();
Console.WriteLine(adder.Add(1, 2));
If that does not work I would inspect the produced dll to verify that it is a conforming .net dll. That should also show the namespaces, class names and other information. A decompiler like dotPeek or ilSpy might show the same information in a format that may be easier to read.
Since your Java class is in the ws package, you should be using ws in your C# code:
using ws;
Adding adding = new Adding();
Console.WriteLine(adding.Add(1, 2));
And if you want to call the Add method statically, declare it static in Java:
package ws;
public class Adding
{
public static int Add(int a, int b)
{
return a + b;
}
}
using ws;
Console.WriteLine(Adding.Add(1, 2));
I want to make a little modification to the Android source to meet my requirement. Here is the requirement:
I want index all the objects in an Android app by adding one more public int field to the java.lang.Object class. Therefore, all the classes can inherit the newly added field because all of them are the subclasses of the Object class.
What I have done so far is modify the java.lang.Object class under <Android_source>/libcore/libart/src/main/java/java/lang folder and recompile the source.
I want to ask if I am doing the right thing. Can my Android app recognize this change (e.g. can a String object access the newly added field)?
Edit
After around 3 weeks try and error, I finally got the complete answer. I want to share this experience with others if anybody else want to modify the core java libraries of Android source (e.g., modifying Object.java and String.java etc.). Again, as mentioned by Michael, please note that such a modification may only be suitable for research or testing purpose.
The key challenge in making a successful modification (here 'successful' means the modified Android source can be built and run on emulators or real devices without any problem) is that some of the classes in the core java library have their C++ mirrors (located in <Android_source>/art/runtime/mirrors/). When modifying these java classes, you should also make the same modifications to their C++ mirrors. Otherwise, you could fail the build process because there are a bunch of checkings that you need to pass. Since I only add a new field to the Object.java, I will list some checkings (or requirements) I encountered below:
1.The size of an object instance = the size of its C++ mirror. For example, if I add a long field into Object.java, I should also add a uint64_t field to its C++ mirror to make their size equal.
2.Try to make the size of an object instance be the power of 2 (e.g., 2, 4, 8, 16, ...). For example, the size of the original Object.java is 8, therefore I add a long field to increase the size to 16. If I add an int field, the size becomes 12 and it can fail many checkings. I don't figure out the exact reason but I guess it has something to do with memory alignment.
3.Try to put primitive-type fields after non-primitive-type fields and primitive-type fields should be ordered by size. This means you should put reference-type fields in the front, followed by 8-byte-primitive-type fields, then 4-byte-primitive-type fields, then 2-byte-primitive-type fields, then 1-byte-primitive-type fields. Again, I guess the reason is memory alignment
That's all I done to meet my requirements. I am open to any discussions if you have any ideas about the purpose of these checkings (especially the 2ed and 3rd one)
New edit
More specifically, I did the following things:
Add a new field (e.g., public long tag;) in Object.java
Change static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 16 : 8; to static constexpr uint32_t kObjectHeaderSize = kUseBrooksReadBarrier ? 24 : 16; in Object.h
Add the following method in Object.h (Only on Android 7)
static MemberOffset TagOffset() {
return OFFSET_OF_OBJECT_MEMBER(Object, tag);
}
Add a new public field public: uint64_t tag; in Object.h
Change
#define MIRROR_OBJECT_CLASS_OFFSET 0
ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value())
#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4
ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value())
#if defined(USE_BROOKS_READ_BARRIER)
#define MIRROR_OBJECT_HEADER_SIZE 16
#else
#define MIRROR_OBJECT_HEADER_SIZE 8
to
#define MIRROR_OBJECT_CLASS_OFFSET 0
ADD_TEST_EQ(MIRROR_OBJECT_CLASS_OFFSET, art::mirror::Object::ClassOffset().Int32Value())
#define MIRROR_OBJECT_LOCK_WORD_OFFSET 4
ADD_TEST_EQ(MIRROR_OBJECT_LOCK_WORD_OFFSET, art::mirror::Object::MonitorOffset().Int32Value())
#define MIRROR_OBJECT_CLASS_TAG 8
ADD_TEST_EQ(MIRROR_OBJECT_CLASS_TAG, art::mirror::Object::TagOffset().Int32Value())
#if defined(USE_BROOKS_READ_BARRIER)
#define MIRROR_OBJECT_HEADER_SIZE 24
#else
#define MIRROR_OBJECT_HEADER_SIZE 16
in asm_support.h (Only on Android 7)
Add addOffset(OFFSETOF_MEMBER(mirror::Object, tag), "tag"); in class_linker_test.cc
Change
static_assert(kObjectHeaderSize == sizeof(mirror::HeapReference<mirror::Class>) +
sizeof(LockWord),
to
static_assert(kObjectHeaderSize == sizeof(mirror::HeapReference<mirror::Class>) +
sizeof(LockWord) + 8,
in art/runtime/gc/collector/concurrent_copying.cc
8 Change static constexpr size_t kFirstElementOffset = 12u; to static constexpr size_t kFirstElementOffset = 20u; in array.h
9 Change static constexpr size_t kObjectAlignmentShift = 3; to static constexpr size_t kObjectAlignmentShift = 4; in runtime_globals.h (Not done yet)
10 Change
static_assert(kObjectAlignment == 8, "Alignment check");
class PACKED(8) ImageHeader {
to
static_assert(kObjectAlignment == 16, "Alignment check");
class PACKED(16) ImageHeader {
in image.h (Not done yet)
11 Change static constexpr size_t kAlignment = 8; to static constexpr size_t kAlignment = 16; in gc::space::BumpPointerSpace (Not done yet)
12 Change #!/usr/bin/python to #!/usr/local/bin/python in device/generic/goldfish/tools/mk_combined_img.py (The value depends on your /bin/env python)(Only on Android 10)
13 Change
#define DCHECK_ALIGNED_PARAM(value, alignment) \
DCHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value)
to
#define DCHECK_ALIGNED_PARAM(value, alignment) \
DCHECK(::art::IsAlignedParam(value, alignment)) << reinterpret_cast<const void*>(value) << "," << alignment
in art/libartbase/base/bit_utils.h (for debug purpose)(Only for Android 11)
14 Change
DCHECK_ALIGNED_PARAM(remaining_space, object_class->GetObjectSize());
Object* end = dst + remaining_space / object_class->GetObjectSize();
to
DCHECK_ALIGNED_PARAM(remaining_space, kObjectAlignment);
Object* end = dst + remaining_space / kObjectAlignment;
in art/dex2oat/linker/image_writer.cc (Only for Android 11)
Change
memcpy(reinterpret_cast<uint8_t*>(to_ref) + kObjectHeaderSize,
reinterpret_cast<const uint8_t*>(from_ref) + kObjectHeaderSize,
obj_size - kObjectHeaderSize);
to
memcpy(reinterpret_cast<uint8_t*>(to_ref) + kObjectHeaderSize - 8,
reinterpret_cast<const uint8_t*>(from_ref) + kObjectHeaderSize - 8,
obj_size - kObjectHeaderSize + 8);
in concurrent_copying.cc (on Android 10)(reference)
Firstly, I'd like to state that I don't think this is a good idea and is probably overkill outside of research purposes. If you are modifying AOSP then the code you write will be dependent on the target device running that customised build of AOSP. However, it is still possible.
I'm assuming you already know how to compile and flash a custom AOSP build to a device. In order to write code that makes use of your new functionality, you'll also need to compile a custom SDK. This is so that Android Studio will know that your new method exists within Object, and can compile correctly against it. The full documentation can be found here, but essentially it boils down to:
. build/envsetup.sh
lunch sdk-eng
make sdk
When you have your SDK zip file, you'll need to unzip it to your SDK's platforms directory - it should now show up checked in your SDK manager. If you have given your SDK a custom platform ID then you should be able to use that in your build.gradle files.
Disclaimer: This advice is purely from memory, it's a lengthy process so I've not had time to double-check, and chances are there may be a couple of minor things I've missed. This should get you most of the way towards where you want to be though.
I'm trying to connect to Teradata through RStudio, but for some reason JDBC function has problems recognizing the path where Java drivers sit. See the code below:
library(RODBC)
library(RJDBC)
library(rJava)
# both Java drivers definitely exist
file.exists('/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/tdgssconfig.jar')
[1] TRUE
file.exists('/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/terajdbc4.jar')
[1] TRUE
But when I paste those paths in JDBC call...
# allow more elaborated error messages to appear
.jclassLoader()$setDebug(1L)
drv = JDBC("com.teradata.jdbc.TeraDriver","/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/tdgssconfig.jar;/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/terajdbc4.jar")
... I get the following error:
RJavaClassLoader: added
'/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/tdgssconfig.jar;/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/terajdbc4.jar'
to the URL class path loader WARNING: the path
'/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/tdgssconfig.jar;/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/terajdbc4.jar'
does NOT exist, it will NOT be added to the internal class path!
RJavaClassLoader: added
'/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RJDBC/java/RJDBC.jar'
to the URL class path loader RJavaClassLoader: adding Java archive
file
'/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RJDBC/java/RJDBC.jar'
to the internal class path
RJavaClassLoader#3d4eac69.findClass(com.teradata.jdbc.TeraDriver)
- URL loader did not find it: java.lang.ClassNotFoundException: com.teradata.jdbc.TeraDriver
RJavaClassLoader.findClass("com.teradata.jdbc.TeraDriver")
- trying class path "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java"
Directory, can get
'/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rJava/java/com/teradata/jdbc/TeraDriver.class'?
NO
- trying class path "/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RJDBC/java/RJDBC.jar"
JAR file, can get 'com/teradata/jdbc/TeraDriver'? NO
ClassNotFoundException Error in .jfindClass(as.character(driverClass)[1]) : class not found
Running the same code in R, rather than RStudio, returns the same error.
Also, re-installing RJDBC package (as suggested here) didn't solve the issue.
Can anyone explain why this is happening? Thanks for help.
Here's my session info:
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.3
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.13.4 RJDBC_0.2-7 rJava_0.9-9 DBI_0.8 RODBC_1.3-15
[6] dplyr_0.7.4 readr_1.1.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.15 bindr_0.1 magrittr_1.5 hms_0.3 R6_2.2.2
[6] rlang_0.1.6 httr_1.3.1 tools_3.4.1 git2r_0.19.0 withr_2.1.1.9000
[11] yaml_2.1.16 assertthat_0.2.0 digest_0.6.15 tibble_1.4.2 bindrcpp_0.2
[16] curl_3.0 memoise_1.1.0 glue_1.2.0 compiler_3.4.1 pillar_1.1.0
[21] pkgconfig_2.0.1
That's a mistake in the path - you have inadvertently pasted two paths together (note the semicolon between the paths). You probably intended
drv <- JDBC("com.teradata.jdbc.TeraDriver",
c("/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/tdgssconfig.jar",
"/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/terajdbc4.jar"))
note that you probably can make your life easier by simply using
drv <- JDBC("com.teradata.jdbc.TeraDriver", Sys.glob("/Users/KULMAK/Documents/TeraJDBC__indep_indep.16.10.00.03/*.jar"))
This worked for me. Just make sure that both jars are located in the referenced directory.
library(RJDBC)
drv <- RJDBC::JDBC(driverClass = "com.teradata.jdbc.TeraDriver", classPath = Sys.glob("~/drivers/teradata/*"))
conn <- dbConnect(drv,'jdbc:teradata://<server>/<db>',"un","pw")
result.df<- dbGetQuery(conn,"select * from table")
OS: Ubuntu 16.04
JNA: 4.2.X
JDK: 1.8.0u111
I'm trying to get the currently focused window programmaticaly on a JavaFX application.
if (Platform.isLinux()) {
final X11 x11 = X11.INSTANCE;
final XLib xlib = XLib.INSTANCE;
X11.Display display = x11.XOpenDisplay(null);
X11.Window window = new X11.Window();
Pointer pointer = Pointer.NULL;
xlib.XGetInputFocus(display, window, pointer); // << ERROR
X11.XTextProperty name = new X11.XTextProperty();
x11.XGetWMName(display, window, name);
System.out.println(name.toString());
}
public interface XLib extends StdCallLibrary {
XLib INSTANCE = (XLib) Native.loadLibrary("/usr/lib/x86_64-linux-gnu/libX11.so", XLib.class);
int XGetInputFocus(X11.Display display, X11.Window focus_return, Pointer revert_to_return);
}
But it doesn't work and throws this exception :
java.lang.IllegalArgumentException: Unrecognized calling convention: 63
at com.sun.jna.Native.invokeInt(Native Method)
at com.sun.jna.Function.invoke(Function.java:390)
at com.sun.jna.Function.invoke(Function.java:323)
at com.sun.jna.Library$Handler.invoke(Library.java:236)
at com.sun.proxy.$Proxy1.XGetInputFocus(Unknown Source)
at application.Main.start(Main.java:33)
Is this line correct ?
XLib INSTANCE = (XLib) Native.loadLibrary("/usr/lib/x86_64-linux-gnu/libX11.so", XLib.class);
I tested with an older version of JNA (4.1.X) and the error changed for :
Unrecognized calling convention: 1
Debug log with -Djna.debug_load=true
Looking in classpath from sun.misc.Launcher$AppClassLoader#73d16e93 for /com/sun/jna/linux-x86-64/libjnidispatch.so
Found library resource at jar:file:/home/puglic/eclipse/jna-4.2.2.jar!/com/sun/jna/linux-x86-64/libjnidispatch.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
Looking for library 'X11'
Adding paths from jna.library.path: null
Trying libX11.so
Found library 'X11' at libX11.so
java.lang.IllegalArgumentException: Unrecognized calling convention: 63
Your XLib definition uses StdCallLibrary, which only makes sense on 32-bit windows systems. It should simply be Library, or derive from the JNA contrib-defined version.
You're basically asking for a calling convention that does not exist.
i have problem when initialize report in program at startup.
Sometime ago, it works correctly. But when i unistall JDK 1.7 update 17 to JDK 1.7 update 21, and fresh install Netbeans , the Exception exist :(
This is the error message :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:609)
at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:455)
at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLineBreakIndex(SimpleTextLineWrapper.java:561)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.measureExactLine(SimpleTextLineWrapper.java:535)
at net.sf.jasperreports.engine.fill.SimpleTextLineWrapper.nextLine(SimpleTextLineWrapper.java:517)
at net.sf.jasperreports.engine.fill.TextMeasurer.renderNextLine(TextMeasurer.java:649)
at net.sf.jasperreports.engine.fill.TextMeasurer.renderParagraph(TextMeasurer.java:454)
at net.sf.jasperreports.engine.fill.TextMeasurer.measure(TextMeasurer.java:395)
at net.sf.jasperreports.engine.fill.JRFillTextElement.chopTextElement(JRFillTextElement.java:541)
at net.sf.jasperreports.engine.fill.JRFillTextField.prepare(JRFillTextField.java:641)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.prepareElements(JRFillElementContainer.java:331)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:379)
at net.sf.jasperreports.engine.fill.JRFillBand.fill(JRFillBand.java:353)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:458)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:421)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:282)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:822)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:61)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:446)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:276)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:745)
at com.ikbiz.gastroscope.controller.ReportController.initReport(ReportController.java:180)
at com.ikbiz.gastroscope.controller.ReportController.<init>(ReportController.java:111)
at com.ikbiz.gastroscope.view.PanelScope.<init>(PanelScope.java:32)
at com.ikbiz.gastroscope.view.PanelEntry.initComponents(PanelEntry.java:199)
at com.ikbiz.gastroscope.view.PanelEntry.<init>(PanelEntry.java:86)
at com.ikbiz.gastroscope.view.Application.initComponents(Application.java:203)
at com.ikbiz.gastroscope.view.Application.<init>(Application.java:35)
at com.ikbiz.gastroscope.view.Application.getInstance(Application.java:43)
at com.ikbiz.gastroscope.view.Application.main(Application.java:79)
Java Result: 1
And this is my code to initialize report.
public void initReport() {
try {
param.put("noMr", "0000");
param.put("visitCode", "V-199208300000");
param.put("templateLoco", iReportDir);
param.put("tools", "Tools");
param.put("medicine", "Medicine");
param.put("result", "Data hasil disini");
param.put("conclusion", "Data kesimpulan disini");
param.put("suggestion", "Suggestion");
param.put("SUBREPORT_DIR",iReportDir);
String imageLoco = iReportDir +"image-sample.jpg";
for (int i = 0; i < 20; i++) {
FileInputStream image = new FileInputStream(imageLoco);
param.put("imgResult"+(i+1), image);
}
param.put("emptyImg", iReportDir+"logo.jpg");
setTemplate("data/reports/templates/template_1.jasper");
jasperPrint = JasperFillManager.fillReport(getTemplate(), param, DatabaseUtility.getConnection());
} catch (JRException ex) {
System.out.println(ex.getMessage());
} catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
But, the And when I build to. Jar, the error disappears.
Please help, thanks before :)
Are you using the Calibri font? I've found that this is a jdk 1.7.0_21 bug and seems to be specific to Calibri.
Try switching the font to Arial and the error should go away.
If you have lots of reports and subreports to modify, this might help:
find . *.jrxml -type f -print0 |xargs -0 grep -lZ "Calibri" |xargs -0 sed -i 's/Calibri/Arial/g'
I have an application that also calls into the same JasperFillManager method and I can confirm that I see the same stacktrace in jdk 1.7_0_21. If I changing the jdk to 1.7_0_17 or 1.7_0_07 the error does not occur.
The class is in the rt.jar and as far as I know, source is not available. But 1.7 was based on openjdk and very similar source can be found at jdk7src.
Debugging the application, I can see that createCharinfo gets a StandardGlyphVector object and queries it for the number of glyphs, which returns 0. StandardGlyphVector.getGlyphCharIndices(0,0,null) then returns a non-null but empty array. The sun.font.ExtendedTextSourceLabel code doesn't check for null or empty array return cases and tries to access into the array which correctly throws the AIOOBE.
There seems to be a related bug report here.
I've also run into this issue and done a bit more testing on this. Here's the findings in short, but I've also commented on the OTN thread.
effected by the 1.6.0u45 and 1.7.0u21 Windows JVMs
only effected by the Calibri, Calibri Bold, Calibri Bold Italic, Calibri Italic and Cambria Bold fonts
most likely fixed in the non-public 1.6.0u51
fixed in 1.7.0u25
We were upgrading our jdk from b24 to b27 version of 1.6.
As we found the same problem, we got it fixed by font changes as following:
In iReport designer, for any element if we don't specify the font properties (fontName and fontSize), it will be set to default.
Hope this was giving problem.
So, we "specified the font properties (esp. fontName) for every element in each of our reports" and tried.
This has fixed the problem.
Root cause as expected:
In older versions of jdk the font manager is handling the default properties for the elements where font property is not specified.
In latest versions, may be the jdk is not able to handle the default font properties.