How can I add java client library in java on netbeans? - java

Hello i read that I have to use the java client library in java to get the revisions list in google drive using google api. I use netbeans. I search for this question and I try to add the bib but i haven't get success. To download the library i visited this link and downloaded the "latest". but after add the jar files I get the message error that the package doesnt exist. Please someone help me!
Yes! I try this but it show the same erros. I add the lib but netbeans (8) show the error in the three lines code: "package [name] doesn't exist".
The three lines are these:
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
obs: the full code, taken in the google developers site is:
package javaapplication8;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
import java.io.IOException;
import java.util.List;
public class MyClass {
private static List<Revision> retrieveRevisions(Drive service,
String fileId) {
fileId = "1XpNdeTFBr2KygyfPtlowBvkpcaJJzjgLckrGjp5oOhg0";
try {
RevisionList revisions = service.revisions().list(fileId).execute();
return revisions.getItems();
} catch (IOException e) {
System.out.println("An error occurred: " + e);
}
return null;
}
}

If it is the error like package is missing, please check whether you have created a folder named com in your project or not. Also, every dot (.) indicates the levels of packages that you use in your project. Please check that com folder followed by the other folder names after every dot are present or not. I think this might help you. I answered your question based on my understanding (i.e, package issue which will be resolved by creating folders in your project. folders means packages). I am sorry if I gave you the wrong answer.

Related

Using Batik 1.14 with Java: How to import modules or classes?

The purpose of my project is to create PNG pictures from SVG using specific fonts (I have tried numerous converter services on the web but none of them worked with external fonts, and the JAVA program I have developed 10 years ago does no longer work).
My actual problem is the import of the batik.transcoder components into my program. Currently, it looks as follows:
<code>
// is this the really the parent of JPEGTranscoder / PNGTranscoder??
import javax.imageio.ImageTranscoder;
// Neither org.apache.batik... nor batik... is correct !!??
import org.apache.batik.transcoder.SVGAbstractTranscoder;
import batik.transcoder.TranscoderException;
import batik.transcoder.TranscoderInput;
import batik.transcoder.TranscoderOutput;
import batik.transcoder.PNGTranscoder;
import batik.transcoder.image.JPEGTranscoder;<br>
// or did I import the wrong jars ??
// (taken from batik-1.14 and afterwards from batik-1.7; neither did work!)
public class SVGConverter {
...
// all code lines below return the same error: "... cannot be resolved to a type"
TranscoderInput input = new TranscoderInput(svgURI);
TranscoderOutput output = new TranscoderOutput(ostream);
ImageTranscoder t;
...
t = new JPEGTranscoder();
...
t = new PNGTranscoder();
...
}
</code>
First I tried to import the batik components as modules on the module path but without success. In a contribution to stackoverflow I then found the hint to put the batik components not onto the module path but to the class path (Has batik not been converted into modules?). However, no success either.
I have copied all jar's contained in batik-1.14.zip and later of batik-1.7.zip into the lib directory within the project. No effect whatsoever...
I was using "import org.apache.batik.transcoder.XXX" in my previous program in 2013: Doesn't work any more. But using "import batik.transcoder.XXX" doesn't work either.
Thus, the following questions:
1. Is it correct that batik classes/jars have to be used via the class path?
2. What is the correct package name to address the respective packages and classes?
3. Is it correct to load the corresponding jar's into the lib directory of the project?

How do I get 'import java.net.*' to work?

I am learning to program in java. I have programmed in other languages. I have tried import java.net.*; at the start of my code file. But it ghosts out. I have looked in my External Libraries directory and it is not there. I found that java.net was deprecated in 201x <-- some recent year. I am using jdk 10. I am using IntelliJ IDE. I have gotten some import statements to work.
I saw on github that they took over hosting oracle classes that were deprecated at Oracle.
I know I have to use the classpath command if I put the .jar or the .zip file containing the class in another directory. I have searched my laptop and i don't have any other .jar or .zip files other than specific other programs I have installed which also don't contain the java.net class (e.g. Aptana Studio 3)
I am using Mac with OS Sierra.
package com.robinhoodcomputer.myfirstprojects;
import java.io.FileReader; <<-- these import ok
import java.io.*;
import java.net.*; <<--- these don't import
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class Myreader {
public static void main(String[] args) throws Exception {
int intVal;
char myChar;
String st;
File file = new File("/java/file");
BufferedReader br = new BufferedReader(new FileReader(file));
// FileReader fr = new
FileReader("/java/HelloWorld/resources/file.txt");
while ((intVal = br.read()) != -1) {
myChar = (char) intVal;
System.out.print(myChar);
}
myHostName = getLocalHost(); <<-- this doesn't show being available
}
}
I have searched and cannot find any articles that actually do anything but explain how to connect to the class file and that you have to import it in your code. No one talks about getting the java.net class itself.
I found one reference to jdk.net in an oracle jdk 10 API specification page.
What am I suppose to use to get the IP address using a hostname in java these days??
thx
P.S. I know this code really doesn't have anything to do with networking, most of it is just reading a file and displaying what's in the file. I wanted to use this code file just to try getting an IP address also. My question is mainly just about making the import statement to work. thx
Your imports are grayed out, since you do not call any method of the imported libraries. As soon as you start using the getLocalHost() method properly, the import will not be grayed out any more. This is a convenience functionality of your IDE it seems.
getLocalHost() is a method of InetAddress and can't be just called without such an instance.
Look at this question for how to use this:
java InetAddress.getLocalHost(); returns 127.0.0.1 ... how to get REAL IP?

Obtianing output of NeurophStudio - import error (java)

I am trying to abtain the output (for example: cat: 0,988; dog: 0.012) from NeurophStudio using java. The neural net recognises the images well. I found the code below. I get errors in the first two import lines. Does anyone know where I can find/download these packages? I searched through all my directories already and didn't find it.
import org.neuroph.core.NeuralNetwork; // ! error
import org.neuroph.contrib.imgrec.ImageRecognitionPlugin; // ! error
import java.util.HashMap;
import java.io.File;
import java.io.IOException;
public class ImageRecognitionSample {
public static void main(String[] args) {
// load trained neural network saved with Neuroph Studio (specify some existing neural network file here)
NeuralNetwork nnet = NeuralNetwork.load("Neural Networks/Iconnet25-8.nnet"); // load trained neural network saved with Neuroph Studio
// get the image recognition plugin from neural network
ImageRecognitionPlugin imageRecognition = (ImageRecognitionPlugin)nnet.getPlugin(ImageRecognitionPlugin.class); // get the image recognition plugin from neural network
try {
// image recognition is done here (specify some existing image file)
HashMap<String, Double> output = imageRecognition.recognizeImage(new File("testimage.png"));
System.out.println(output.toString());
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
source : http://neuroph.sourceforge.net/image_recognition.html
I found the package code here : https://github.com/neuroph/neuroph/tree/master/neuroph-2.9/Core/src/main/java/org/neuroph/core
Problem: this is not downloadable and I will probably need multiple files/entire package.
Does anyone have experience with this? Any solutions?
download neuroph.jar
then locate it to your project
like this
right click on your project
properties
Libraries
add jar/folder
then show the path where you put the neuroph.jar
hope it will help you!!!!

Jackcess compilation error

i have been searching around for a few days for the answer to this and i just can't seem to get it to work. I have seen exact examples where it is working for them and I try exactly what they do and it is just not working for me.
Basically what i am trying to do is open a local access DB. I have tried numerous methods and this Jackcess seems by far the best library to use, so i am trying to get it to work with that. I have read their cookbook and gone through all of that, and still no luck so i am coming to you guys in the hope of finding a good solution (i have not posted this question anywhere yet). Here is my code (the relevant part)
The only syntax error i am getting is "DatabaseBuilder.Open" and the error is it cannot find the method, even though i have the libraries included for IO
import com.healthmarketscience.jackcess.*;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Database db = DatabaseBuilder.open(new File("my.mdb"));
try {
Table table = db.getTable("Teams");
} catch (IOException ex) {
Logger.getLogger(Teams.class.getName()).log(Level.SEVERE, null, ex);
}
}
Any help would be greatly appreciated!
The program fails to debug once I have click this buttone the only actual message i can fine is
"Cannot find symbol
Symbol : Method Open(file)
Location : variable.DatabaseBuilder of type Object"
To use Jackcess you must have at least the following items in the build path for your Java project (or on your CLASSPATH):
the Jackcess JAR file itself, and
the JAR files for its two mandatory compile-time dependencies from Apache: commons-lang and commons-logging.
In the Eclipse IDE that will look something like this:

Getting "Source not found" error

I have been trying to fix this problem for more then 3 hours. I have noticed that there are question with similar problem and i have tried everything but its still not working.
I think that the problem has something to do with JSoup JAR file.
Here is link to similar problem How to add Jsoup in my project?
I have tried to set up both Android and normal Java project and same error appears.
EDIT: Here is the code, just in case
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Klasa {
public static void main(String[] args){
try{
String servisURL = "http://www.sczg.unizg.hr/student-servis/";
Document doc = Jsoup.connect(servisURL).get();
Elements jobNode = doc.select("div.jobBox");
System.console().writer().print(jobNode.get(0).text());
}catch(Exception e){
System.out.println(e.getMessage().toString());
}
}
}
EDIT2: I have solved the problem
Just change System.console().writer().print(jobNode.get(0).text());
to
System.out.print(jobNode.get(0).text());
If you are using Eclipse, then follow these steps,
Right click on your project.
Go to Properties -> Java Build Path
Click on the Source tab -> Add Folder button.
Add the source folder of your project.
In case you want to attach an external source like a jar, click on Link Source.

Categories

Resources