|
jschell wrote: Most people will not go to a site to look at your code.
Yeah, I know, but this time, there was a lot of code to show, so I decided to post it in case someone is interested in.
jschell wrote: 2. The definition must match EXACTLY with the expected classes in the native library. Changes to packages, methods, parameters, access, etc, all require regenerating the api, recompiling and building a new native library.
I thought this is the problem, after all, C source code was the same in both cases, only the header file was different, which was generated based on the class from java.
jschell wrote: You can achieve the same functionality using an external executable and accessing via any number of methods such as stdin/out, files, sockets or even running it as a true service (http, rest, etc)
This can be a good alternative, tho I would have to make sure that the external executable finished what was supposed to do, before Java continues with the rest of the code.
jschell wrote: It is possible to validate that a native library loads (1 above) and this should ALWAYS be verified. Methods should be wrapped in a proxy class so that that mismatches (2) can be captured an properly reported as being mismatches.
Yeah, that would be a mistake not to do, and I'm sure quite a few times it is made, being from laziness or a different reason.
Thanks for your response.
|
|
|
|
|
Hi, When I'm trying to create a header file (using javac -h . ClassName.java), I have 2 problems.
1: I get an error that there are some unmappable character for encoding Cp1250, but I think this problem I solved it by adding -encoding utf8 at the end;
2: I have more then 1 package and because of this I get the following error for every usage of a class that is in a different package.
ClassName.java:lineNumber: error: cannot find symbol
function header
symbol: variable TheNameOfTheVariable
location: class TheNameOfTheClass
The first problem I think it is solved by adding that at the end, but I don't know what to do for the 2nd problem. Any suggestions?
modified 9-Jun-18 16:42pm.
|
|
|
|
|
Do you mean using javap? And without seeing some code and the actual output, it is impossible to guess.
|
|
|
|
|
I said "javac -h" to create a header file, so I can create the DLL in C.
public class TestMain extends Application {
static {
System.load(System.getProperty("user.dir") + "\\Data\\Example.dll");
}
private native void doSomething();
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage arg0) throws Exception {
Class1 example1 = new Class1();
Class2 example2 = new Class2();
doSomething();
arg0.setScene(new Scene(new Pane()));
arg0.show();
}
}
Class1 and Class2 only have the constructor in them. Also they are in "\Example\src\NewPackage" compared to the TestMain which is in "\Example\src\Test".
Here is the command output:
Link to image
|
|
|
|
|
By using javac -cp "Path To src Folder" I don't get that error anymore, but now, even tho the classes are saved as UTF-8, and that I added -encoding utf8 (I tried -encoding utf-8 too), I still get "error: unmappable character for encoding utf-8"
|
|
|
|
|
There must be some strange characters still in your source files.
|
|
|
|
|
I just did a test with the same characters in another project, and I don't have that problem, it is really strange. Oh well, I'll figure it out in time.
|
|
|
|
|
There must be a character in there somewhere that is not getting displayed. Use a hex editor to find it.
|
|
|
|
|
The problem was from Eclipse. I had to remove those characters and then add them again. For some reason it wasn't recognizing then anymore and was adding some weird characters instead in the files.
|
|
|
|
|
So, the solution was to add:
-cp "The location of src folder" (you need the " ")
-encoding utf8
|
|
|
|
|
I am doing a project in java that requires to detect the number of fingers in the image
I want to know how to do that or sample code for this task .
|
|
|
|
|
Google for "Java image recognition".
|
|
|
|
|
i had starting learning java one month age but till now i dont think i had gain even 1% of knowledge please help
|
|
|
|
|
|
Hi,
I'm in a full stack training program and we are currently working on an inter-team project comprised of RESTful services in a microservice architecture. I've been put in charge of back-end unit testing for and am currently researching various test APIs. In addition to JUnit, I'm trying to determine whether I should use REST-assured, Mockito, or both. Reading through the documentation and reading/watching various tutorials has been a bit confusing though. My understanding so far is that REST Assured is for endpoint testing and Mockito is for unit testing. Can someone please give advice as to which would be better to use, or should I be using them both?
Basically, it would be for testing basic CRUD functionality in Spring MVC apps on the service and controller layers.
Any help or advice is greatly appreciated! Also, I can provide more information if you want, I realize it's kind of an open-ended question.
|
|
|
|
|
|
This is the Java forum. What language is that code in your picture?
|
|
|
|
|
It's written in "spam".
The words "tick to view" are a link to an essay writing site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I (foolishly) assumed it was a single link.
|
|
|
|
|
Hey guys!
I'm just trying to figure out this homework and could use some help. Not looking for answers really, just a better understanding. I'm very very new to coding, using jGRASP java. The teacher told us to create this game that generates an output similar to this.
Round 1:
• Player A rolls: 1,2, the highest number is 21
• Player B rolls: 2,1, the highest number is 21
• Result: draw
• Round 2:
• Player A rolls: 2,5, the highest number is 52
• Player B rolls: 6,8 the highest number is 86
• Result: Player B wins
• Round 3:
• Player A rolls: 1,9, the highest number is 91
• Player B rolls: 9,9 the highest number is 99
• Result: Player B wins
• Final Result: Player B wins!!!
Do I have to declare the numbers as Strings to concatenate them? and do I use if else statements? Specifically, I'm confused on how to arrange the two numbers if one is greater than the other so the greater number will be placed in front.
import java.util.Scanner;
import java.util.Random;
public class beatThat
{
public static void main(String[] args)
{
Random r1 = new Random();
Random r2 = new Random();
Random r3 = new Random();
Random r4 = new Random();
int die1 = r1.nextInt(6) + 1;
int die2 = r2.nextInt(6) + 1;
int die3 = r3.nextInt(6) + 1;
int die4 = r4.nextInt(6) + 1;
System.out.println("ROUND 1");
System.out.println("Player A rolls: " + die1 + " and " + die2 +".");
System.out.println("Player B rolls: " + die3 + " and " + die4 +".");
if(die1 >= die2)
{
System.out.println("Player A's highest number is: " + die1 + die2);
}
else if (die2 >= die1)
{
System.out.println("Player A's highest number is: " + die2 + die1);
}
if(die3 >= die4)
{
System.out.println("Player B's highest number is: " + die3 + die4);
}
else if(die4 >= die3)
{
System.out.println("Player B's highest number is: " + die4 + die3);
}
}
}
Anything helps, thank you guys.
Have a good day!
modified 6-May-18 14:51pm.
|
|
|
|
|
Your call to nextInt returns a number in the range [0..5] so you will end up with a number in the range [1..6], so you can never roll an 8 or a 9, as specified in your examples.
To get the highest number you need to write a method which takes two numbers and returns the relevant value. The algorithm for this is fairly straightforward. Compare the two numbers to get the higher number (or either one if they are equal). Multiply the higher number by 10 and add the lower, which gives the "highest" value.
|
|
|
|
|
Hi. For the question below I wrote a code which you can see and it has an unknown error. I appreciate if someone can tell me where the problem is. Thanks.
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
class Solution {
public boolean isSymmetric(TreeNode root) {
boolean flag = false;
if (root == null) return true;
if(root.left == root.right != null)
flag = twoSymmetric(root.left , root.right);
retrun flag;
}
public boolean twoSymmetric(TreeNode left , TreeNode right){
if (left.left.val == right.right.val != null && left.right.val == right.left.val != null) return twoSymmetric(left.left , right.rigth) && twoSymmetric(left.right , right.left);
else return false;
}
}
|
|
|
|
|
It is not clear what your node structure is, but at a guess your code needs modifying to something like:
public boolean twoSymmetric(TreeNode left , TreeNode right){
if (left.val == right.val) {
if (left.left != null && right.right != null) {
if (twoSymmetric(left.left, right.right) {
if (left.right != null && right.left != null) {
return (twoSymmetric(left.right , right.left);
}
}
}
}
return false;
}
|
|
|
|
|
Text files like this:
1.txt :
cronie-anacron::1.4.11::17.el7::x86_64::Friday 05 January 2018 11:13:34 AM IST
2.txt :
accountsservice :: 0.6.40-2ubuntu11.3 :: None :: amd64 :: None
|
|
|
|
|