14.02.2016, 17:06
@mk124, found an issue with passing arrays to java function - it is impossible to pass other values except for an array and size of the array to java function. Server is being crashed.
Java code:
The next message follows after calling the java function from pawn:
Pawn code (I'm not sure that the problem is in here):
Also, I tried to move first parameter to the last, and it's worked, but after execution of java function I get NullPointerException message:
Java code:
Pawn code (remains the same, just moved 33 to the end):
Console's messages:
Or maybe I did something wrong when passing any value to the java function?
Java code:
PHP код:
instance.registerFunction("java_TestArray", objects -> {
int someValue = (Integer) objects[0]; // in this line the java.lang.ClassCastException is being thrown (read below)
Integer[] array = (Integer[])objects[1];
for (int i = 0; i < array.length; i++) {
if(someValue == 33) {
array[i] = (i + 2) * 4;
} else {
array[i] = i+1;
}
}
return 1;
}, Integer.class, Integer[].class, Integer.class);
Код:
[19:57:52][ERROR][err] java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to java.lang.Integer [19:57:52][ERROR][err] at com.infected_wars.iw.common.utils.pawn.methods.ItemMethods.lambda$registerPawnFunctions$46(ItemMethods.java:47) [19:57:52][ERROR][err] at net.gtaun.shoebill.amx.AmxInstanceImpl.callRegisteredFunction(AmxInstanceImpl.java:67) [19:57:52][ERROR][err] at net.gtaun.shoebill.SampEventDispatcher.onRegisteredFunctionCall(SampEventDispatcher.java:2143) [19:57:52][ERROR][err] at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$null$334(SampCallbackManagerImpl.java:847) [19:57:52][ERROR][err] at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:21) [19:57:52][ERROR][err] at net.gtaun.shoebill.util.TryUtils.tryTo(TryUtils.java:14) [19:57:52][ERROR][err] at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.lambda$onRegisteredFunctionCall$335(SampCallbackManagerImpl.java:847) [19:57:52][ERROR][err] at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184) [19:57:52][ERROR][err] at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) [19:57:52][ERROR][err] at java.util.concurrent.ConcurrentLinkedQueue$CLQSpliterator.forEachRemaining(ConcurrentLinkedQueue.java:851) [19:57:52][ERROR][err] at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) [19:57:52][ERROR][err] at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) [19:57:52][ERROR][err] at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) [19:57:52][ERROR][err] at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) [19:57:52][ERROR][err] at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) [19:57:52][ERROR][err] at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) [19:57:52][ERROR][err] at net.gtaun.shoebill.samp.SampCallbackManagerImpl$1.onRegisteredFunctionCall(SampCallbackManagerImpl.java:847) [debug] Server crashed while executing bare.amx [debug] AMX backtrace: [debug] #0 native CallShoebillFunction () from Shoebill.DLL [debug] #1 00000230 in public TestArrayFunction () at D:\Backup of flash card\all for California RolePlay\Survival Project\Java server test\gamemodes\bare.pwn:40 [debug] Native backtrace: [debug] #0 526e8ef9 in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll [debug] #1 52747f5b in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll [debug] #2 52749ddc in ?? () from C:\Program Files (x86)\Java\jdk1.8.0_65\jre\bin\server\jvm.dll [debug] #3 52c88e2b in ?? () from plugins\Shoebill.DLL [debug] #4 52c8695b in ?? () from plugins\Shoebill.DLL [debug] #5 004010b6 in ?? () from samp-server.exe [debug] #6 52d562ca in ?? () from plugins\crashdetect.DLL [debug] #7 52d58b28 in ?? () from plugins\crashdetect.DLL [debug] #8 52d509c7 in ?? () from plugins\crashdetect.DLL [debug] #9 52d5631a in ?? () from plugins\crashdetect.DLL [debug] #10 546f51b9 in ?? () from plugins\streamer.DLL [debug] #11 52cac974 in ?? () from plugins\Shoebill.DLL [debug] #12 100012ad in ?? () from plugins\fixes2.DLL [debug] #13 00469a46 in ?? () from samp-server.exe [debug] #14 0048d46b in ?? () from samp-server.exe [debug] #15 0049b431 in ?? () from samp-server.exe [debug] #16 0049b441 in ?? () from samp-server.exe
PHP код:
new array[32];
CallShoebillFunction("java_TestArray", 33, array, sizeof(array));
for(new i = 0; i < 32; i++) {
printf("array[%d] = %d", i, array[i]);
}
Java code:
PHP код:
instance.registerFunction("java_TestArray", objects -> {
int someValue = (Integer) objects[2];
Integer[] array = (Integer[])objects[0];
for (int i = 0; i < array.length; i++) {
if(someValue == 33) {
array[i] = (i + 2) * 4;
} else {
array[i] = i+1;
}
}
return 1;
}, Integer[].class, Integer.class, Integer.class);
PHP код:
new array[32];
CallShoebillFunction("java_TestArray", array, sizeof(array), 33);
for(new i = 0; i < 32; i++) {
printf("array[%d] = %d", i, array[i]);
}
return 1;
Код:
array[0] = 8 array[1] = 12 array[2] = 16 array[3] = 20 array[4] = 24 array[5] = 28 array[6] = 32 array[7] = 36 array[8] = 40 array[9] = 44 array[10] = 48 array[11] = 52 array[12] = 56 array[13] = 60 array[14] = 64 array[15] = 68 array[16] = 72 array[17] = 76 array[18] = 80 array[19] = 84 array[20] = 88 array[21] = 92 array[22] = 96 array[23] = 100 array[24] = 104 array[25] = 108 array[26] = 112 array[27] = 116 array[28] = 120 array[29] = 124 array[30] = 128 array[31] = 132 [20:06:02][ERROR][err] java.lang.NullPointerException

