I try to to create DbxEntry object with path that include hebrew character and it's doesn't work.
It's gives me "nullPointerException", Here is example of the code i try to run with main function:
public static void example(String s) throws IOException, DbxException{
auth();
DbxEntry a = client.getMetadata(s);
System.out.println(a.name);
}
public static void main(String [] args) throws IOException, DbxException{
System.out.println("First example: ");
example("/Public");
System.out.println("Working..");
System.out.println("Second example: ");
example("/לשום");
}
The output is:
First example:
Linked account: Itay Velner
Public
Working..
Second example:
Linked account: Itay Velner
Exception in thread "main" java.lang.NullPointerException
at node.Main.example(Main.java:137)
at node.Main.main(Main.java:145)
I tried to look for help in the web and i doesn't find anything yet. if i convert the hebrew String into unicode it's still doesn't work.
I think that there is some problem with the api,
any thoughts?
Thanks,
Itay.
Related
I'm trying to parse (with jsoup) some specific text from a website, but it doesn't work for me.
LINK TO SITE
It's the number "43" in red text that I am interested in at the top-right of the page.
This is what I tried:
String test;
public void scan(String url) throws Exception {
Document document = Jsoup.connect(url).get();
Elements votes = document.select("#malicious-votes .pull-right");
test = votes.text();
}
public int returnVotes(){
return test();
}
~ ~ ~
public static void main(String[] args) throws Exception {
Scan_VirusTotal virustotal = new Scan_VirusTotal();
virustotal.scan("https://www.virustotal.com/sv/url/cbf2d00f974d212b6700e7051f8b23f2038e876173066af41780e09481ef1cdd/analysis/1407146081");
System.out.println(virustotal.returnVotes());
This prints nothing. Other elements work fine with this exact method, so I'm really confused as to why this particular piece of text won't parse.
Ideas? Thanks.
EDIT - added some HTML from page as requested:
<div style="display:block" class="pull-right value text-red" id="malicious-votes">44</div>
Try using this instead:
Elements votes = document.select("#malicious-votes");
test = votes.text();
I tried this $("#malicious-votes .pull-right") in the browser console of the given page, gives me empty array. But $("#malicious-votes") gives me the vote div which itself has the class pull-right.
Your selector should be:
"#malicious-votes", not "#malicious-votes .pull-right".
"#malicious-votes .pull-right" selects any elements with class pull-right that are descendants of #malicious-votes. What you want is the #malicious-votes element itself.
I am new to Java programming, and today while messing with eclim and vim, I discovered that the System.out.println(); function is not working.
class apples{
public static void main(String args[]){
double tuna = 5.28;
System.out.print(tuna);
}
}
This does not give me a result.
But when I do:
class apples{
public static void main(String args[]){
double tuna = 5.28;
System.out.println(tuna);
}
}
(The only difference is the "println")
I get 5.28, the correct behavior.
Anyone know why this would happen, or is this the way it should be happening?
.println() automatically appends a newline, .print() does not.
System.out is a buffered stream; you need to .flush() for the result of .print() to appear (do it after you print, obviously). The newline in .println() causes the output to be flushed, which is why you don't need it there.
I am a bit lost here, i have been searching this for sometime.
I have a string $#897950%-1. Now i need to see if it contains a -1 in it. I tried
str.contains("-1") but it did not work. Can someone guide me to solve this ?
I tried it out as:
public static void main(String ar[]){
String str="$#897950%-1";
System.out.println(str.contains("-1"));
}
And See, what eclipse saw me, (It just work fine and gave me true as output):
Check whether you really have this string. May be debugger or output system replaces something.
I have the following code printing 'true'
public static void main(String[] args) {
String str = "$#897950%-1";
System.out.println(str.contains("-1"));
}
Maybe I'm forgetting an import at the head, but nothing seems to work. I'm trying to learn java and still beginner.
public class Main {
public static void main(String[] args) {
String s1=getInput("Enter First Number") ;
String s2=getInput("Enter second Number");
double d1=Double.parseDouble(s1);
double d2=Double.parseDouble(s2);
double result=d1+d2 ;
System.out.println(result);
}}
results in an error because the compiler doesn't recognize getInput("");
This is from Eclipse:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method getInput(String) is undefined for the type Main
The method getInput(String) is undefined for the type Main
at Main.main(Main.java:8)
You're calling a getInput()-method which doesn't exist in your class. Have a look at this Java tutorial on I/O:
http://docs.oracle.com/javase/tutorial/essential/io/cl.html
"This is from Eclipse:
Exception in thread"
Eclipse should have warned you about this before you compiled the file with a "red" marks. Please fix them before compiling the class.
That is because getInput is not defined. Take a look at this example to see how to get input from a user.
http://www.roseindia.net/java/java-get-example/java-get-user-input.shtml
Try this
import java.io.*;
BufferedReader reader = new BufferedReader(System.in);
String input = reader.readLine();
What could be wrong:
method getInput is not implemented in Main class
getInput is not static, so main doesn't see it (you could change getInput to static method)
getInput doesn't have String signature, so it doesn't take String as parameter
You've probably figured this out by now, but like everyone else has said, it looks like getInput hasn't been implemented. Meaning you haven't told the program what getInput actually does. You'll need an import, and to add the getInput method something like the following:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String s1=getInput("Enter First Number") ;
String s2=getInput("Enter second Number");
double d1=Double.parseDouble(s1);
double d2=Double.parseDouble(s2);
double result=d1+d2 ;
System.out.println(result);
}
private static String getInput(String output)
{
Scanner input = new Scanner(System.in);
System.out.println(output);
return input.next();
}
}
The getInput method here takes that string you send it and calls it 'output.' so output = "Enter First Numer" the first time you call it.
Then you create a Scanner object named 'input', which will allow you to read what the user types in the keyboard.
Scanner input = new Scanner(System.in);
Then you send that output message to the user:
System.out.println(output);
Finally, you return the String that was typed by the user, using your input object that will read the next thing the user types. The user will have to hit enter after typing.
return input.next();
If you have any questions about what's happening there let me know.
import java.io.*;
public class listjava
{
public static void main(String args[]){
Console c = System.console();
char[] pw;
pw = c.readPassword("%s","pw: ");
for (char ch: pw)
c.format("%c ",ch);
c.format("\n");
MyUtility mu = new MyUtility();
while(true)
{
String name = c.readLine("%s","input?: ");
c.format("output : %s \n",mu.doStuff(name));
}
}
}
class MyUtility{
String doStuff (String arg1){
return " result is " + arg1;
}
}
I got an error like this:
Exception in thread "main" java.lang.NullPointerException
at listjava.main(listjava.java:7)
Why is my program wrong?
System.console() is returning null.
Quoting Java's documentation:
Returns the unique Console object associated with the current Java virtual machine, if any.
So, there are probably no console associated to your JVM. You are probably running your program within Eclipse or other IDE. Try running your program from your system's command line. It should work.
To run your program from the command line.
Go to directory where listjava.class resides
Run java's interpreter
$ java listjava
According to the Javadoc for System.console():
Returns: The system console, if any, otherwise null.
So I suppose that System.console() is handing back null and your line
pw = c.readPassword("%s","pw: ");
is therefore dereferencing null. I'm not sure what fix you might want to use; perhaps reading from System.in instead?