This question already has an answer here:
java.lang.NoClassDefFoundError Main (Wrong Name : com/leslie/quiz/Main)
(1 answer)
Closed 8 years ago.
I used the following code to collect tweets. When compile there is no any error. But when I compile this program it shows the exceptions.
package com.crowley.simplestream;
import twitter4j.FilterQuery;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.User;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.StallWarning;
public class SimpleStream {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("*********************");
cb.setOAuthConsumerSecret("*******************");
cb.setOAuthAccessToken("********************");
cb.setOAuthAccessTokenSecret("*********************");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener() {
#Override
public void onException(Exception arg0) {
// TODO Auto-generated method stub
}
#Override
public void onDeletionNotice(StatusDeletionNotice arg0) {
// TODO Auto-generated method stub
}
#Override
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
#Override
public void onStatus(Status status) {
User user = status.getUser();
// gets Username
String username = status.getUser().getScreenName();
System.out.println(username);
String profileLocation = user.getLocation();
System.out.println(profileLocation);
long tweetId = status.getId();
System.out.println(tweetId);
String content = status.getText();
System.out.println(content +"\n");
}
#Override
public void onTrackLimitationNotice(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onStallWarning(StallWarning warning){
}
};
FilterQuery fq = new FilterQuery();
String keywords[] = {"ireland"};
fq.track(keywords);
twitterStream.addListener(listener);
twitterStream.filter(fq);
}
}
The exception which I am getting when I run this program is as follows.
Exception in thread "main" java.lang.NoClassDefFoundError: SimpleStream (wrong name: com/crowley/simplestream/SimpleStream)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:472)
I used Jwitter4j. But it does not contains the packages like ClassLoader.java. What can I do? Please help me.
How is your project set up? Are you compiling and running this from the command line or in an IDE? When you have a class named SimpleStream with a package com.crowley.simplestream; statement at the top, then com.crowley.simplestream.SimpleStream is the fully qualified name of the class. The javac compiler will emit the .class file in the current directory by default, but it expects the class to be found in com/crowley/simplestream/SimpleStream when you run it.
Normally you would keep the source for com.crowley.simplestream.SimpleStream in a file com/crowley/simplestream/SimpleStream.java in your project, typically underneath a src or src/main/java directory, and your IDE (such as Eclipse or IDEA) would build all the source files in that directory into a parallel output directory structure with all the .class files. It sounds like you may be building everything yourself from the command line, which of course you can do, but you must take into account the fully qualified name of the class and where Java then expects to find it.
For example, you could put the source into an appropriate directory and type the full path to it when invoking javac, or you could use the -d switch to javac to tell it where to put the .class file, and you would then use the fully qualified name of the class when running it:
java com.crowley.simplestream.SimpleStream
Related
I'm currently trying to create a procedure in Genexus 15 and call from Java Environment, but when I import the jar file to Java the function cannot be called.
I am creating a simple procedure with a stub as follows:
stub salvadados(in:&StringTeste, out:&StringRetorno)
&StringRetorno = "ola " + &StringTeste
endstub
Genexus is generating the .jar file when deploying the application, then I import it on NetBeans. The import is successfull and it recognizes the procedure I created, but when I access its methods, there's no call for my stub.
My Java class is as follows. I want to call my stub in the Function EnviaDados.
import com.genexus.GXProcedure;
import com.genexus.GXutil;
import com.genexus.ModelContext;
import com.genexus.reports.GXcfg;
import com.kbtesteintegracao.projeto.ptesteintegracao;
public class IntegracaoGenexus extends GXProcedure {
ptesteintegracao ptesteintegracao;
public void executeCmdLine(String args[]) {
execute();
}
public IntegracaoGenexus(int remoteHandle) {
super(remoteHandle, new ModelContext(IntegracaoGenexus.class), "");
}
public IntegracaoGenexus(int remoteHandle, ModelContext context) {
super(remoteHandle, context, "");
}
public void iniciar() {
ptesteintegracao = new ptesteintegracao(remoteHandle, context);
}
public void EnviaDados(String strDados) {
//ptesteintegracao.gxep_salvadados(strDados);
}
public void execute() {
execute_int();
}
private void execute_int() {
initialize();
privateExecute();
}
private void privateExecute() {
new ptesteintegracao(remoteHandle, context).gxep_salvadados("teste");
cleanup();
}
public static Object refClasses() {
GXutil.refClasses(IntegracaoGenexus.class);
return new GXcfg();
}
protected void cleanup() {
CloseOpenCursors();
exitApplication();
}
protected void CloseOpenCursors() {
}
/* Aggregate/select formulas */
public void initialize() {
/* GeneXus formulas. */
Gx_err = (short)(0) ;
}
private short Gx_err ;
}
What I am missing? I appreciate any help.
I've found a solution. What I did was create a test Web Panel on my Genexus project and called the procedure I created. In this WPanel I just put a Button component that triggers the following event:
Event 'Teste'
ptesteintegracao.salvadados("oi", &retorno)
Endevent
I don't know why, but by making this call to my procedure, in some way it forced Genexus to recreate the .java file of my procedure, which it was not doing with the build, rebuild or Build with this only options. When recreated, my java class was with the function corresponding to my procedure stub.
After that, I just deployed the application, generating a new .jar file and imported it on my NetBeans project and my function was available:
ptesteintegracao.gxep_salvadados("teste", stringReturn);
Here it is the correction for question above.
The private execute method needs the output parameter.
This:
new ptesteintegracao(remoteHandle, context).gxep_salvadados("teste");
Should be like this:
new String retorno = new ptesteintegracao(remoteHandle, context).gxep_salvadados("teste");
I am writing a utility class using twitter4j for multiple purpose. I am able to search tweets based on Hashtags, location etc but Streaming API is not working for me.
I have written a class with main method after following a blog as follows but I am getting class not found error.I am new to java.
package mytweetapp;
import twitter4j.FilterQuery;
import twitter4j.StallWarning;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterException;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.conf.ConfigurationBuilder;
public class Stream {
public static void main(String[] args) throws TwitterException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("*****")
.setOAuthConsumerSecret(
"*******")
.setOAuthAccessToken(
"*****")
.setOAuthAccessTokenSecret(
"*****");
TwitterStreamFactory tf = new TwitterStreamFactory(cb.build());
TwitterStream twitter = tf.getInstance();
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
System.out
.println("#" + status.getUser().getScreenName() + " - " + status
.getText());
}
public void onDeletionNotice(
StatusDeletionNotice statusDeletionNotice) {
System.out
.println("Got a status deletion notice id:" + statusDeletionNotice
.getStatusId());
}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
System.out
.println("Got track limitation notice:" + numberOfLimitedStatuses);
}
public void onScrubGeo(long userId, long upToStatusId) {
System.out
.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
public void onException(Exception ex) {
ex.printStackTrace();
}
#Override
public void onStallWarning(StallWarning arg0) {
// TODO Auto-generated method stub
}
};
FilterQuery fq = new FilterQuery();
String keywords[] = { "Mango", "Banana" };
fq.track(keywords);
twitter.addListener(listener);
twitter.filter(fq);
}
Error
Exception in thread "main" java.lang.NoClassDefFoundError: twitter4j/internal/http/HttpClientWrapperConfiguration
at twitter4j.TwitterStreamFactory.<clinit>(TwitterStreamFactory.java:40)
at mytweetapp.Stream.main(Stream.java:23)
Caused by: java.lang.ClassNotFoundException: twitter4j.internal.http.HttpClientWrapperConfiguration
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
My current hypothesis is that the problem is because of mixing core and stream jars of different versions (so e.g. TwitterStreamFactory from stream-3.0.3 expects HttpClientWrapperConfiguration to be available on your classpath but in 4.0.4 it is no longer included. Please try having those of the same version included (and only one version of lib, so stream-3 and stream-4 being included together is no-no). If that won't work - share the whole project somewhere for more context.
As for what classpath is you can google, or read up e.g. here What is a classpath?
I am getting exception : no jsmile in java.library.path when i run my project. Even i have added jsmile_win64 in lib folder and .dll file in vm option : -Djava.library.path="C:\Users\admin\jsmile.dll"; But still I am facing the same issue.
import smile.Network;
import smile.learning.DataMatch;
import smile.learning.DataSet;
import smile.learning.EM;
import smile.learning.GreedyThickThinning;
public class MyClass
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Network _net = new Network();
_net.readFile(workfilehere);
}
}
How to fix this?
It works fine after changed the -Djava.library.path="C:\Users\admin\jsmile.dll"; to -Djava.library.path="C:\Users\admin\"
I have downloaded the Binary model files from here but i am not getting how do i have to set the path. I am using Eclipse, i tried adding these binary file into the path of my project.Second point is,I am not working on Maven Project.
import opennlp.tools.sentdetect.SentenceDetectorME;
import opennlp.tools.sentdetect.SentenceModel;
import opennlp.tools.util.InvalidFormatException;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
public class OpenNlpTest {
public static void SentenceDetect() throws InvalidFormatException,
IOException {
String paragraph = "Hi. How are you? This is Mike.";
// always start with a model, a model is learned from training data
InputStream is = new FileInputStream("en-sent.bin");
SentenceModel model = new SentenceModel(is);
SentenceDetectorME sdetector = new SentenceDetectorME(model);
String sentences[] = sdetector.sentDetect(paragraph);
System.out.println(sentences[0]);
System.out.println(sentences[1]);
is.close();
}
public static void main(String []z){
try {
SentenceDetect();
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
this is the code i am trying to run but it gives the following error
java.io.FileNotFoundException: en-sent.bin (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at OpenNlpTest.SentenceDetect(OpenNlpTest.java:17)
at OpenNlpTest.main(OpenNlpTest.java:31)
This is the hierarchy of my project which i have just started
I got the solution.
This helped me to crack the problem
Basically what I did is I gave the absolute path of the file rather than relative path.
As you can see it is showing
java.io.FileNotFoundException: de-sent.bin (The system cannot find the file specified)
You haven't added necessary dependent libraries.In the link you've provided there is a bin named de-sent.bin.You have to add it to the library path
I'm trying to create a plugin for minecraft bukkit servers. The goal is to read the string on the first line of an html page. If the result is True it will execute a command.
Here is the code I have right now:
import java.net.URLConnection;
import java.util.Scanner;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class main extends JavaPlugin{
public final Logger logger = Logger.getLogger("Minecraft");
public void onEnable(){
logger.info("[First] Has Been Enabled.");
}
public void onDisable(){
logger.info("[First] Has Been Disabled.");
}
public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
Player player = (Player) sender;
if(commandLabel.equalsIgnoreCase("hello")){
player.sendMessage(ChatColor.GOLD + "Hello");
}
else if(commandLabel.equalsIgnoreCase("world")){
player.sendMessage(ChatColor.GOLD + "World");
}
else if(commandLabel.equalsIgnoreCase("coolman")){
player.setPlayerListName("coolman");
}
else if(commandLabel.equalsIgnoreCase("vote")){
String sourceLine = null;
// The URL address of the page to open.
URL address = new URL("http://www.koolflashgames.com/test.php");
// Open the address and create a BufferedReader with the source code.
InputStreamReader pageInput = new InputStreamReader(address.openStream());
BufferedReader source = new BufferedReader(pageInput);
// Append each new HTML line into one string. Add a tab character.
try {
sourceLine = source.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(sourceLine == "False"){
player.sendMessage("Thanks for voting!");
}
}
return false;
}
}
Creates the following error in the log:
2012-11-02 16:18:30 [SEVERE] null
org.bukkit.command.CommandException: Unhandled exception executing command 'vote' in plugin first v1.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180)
at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:502)
at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:915)
at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:828)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:810)
at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111)
at net.minecraft.server.ServerConnection.b(SourceFile:35)
at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:561)
at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
Caused by: java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at me.storminmormon30.first.main.onCommand(main.java:43)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
... 15 more
Looks like the error is somewhere else:
Unhandled exception executing command 'vote'
I don't see that command in the code snippet you have given
You should split each command into it's own class and register in in the plugin.yml, What I would do, is in the onEnable() method, set something like this:
getCommand("command").setExecutor(new CommandExecutor());
That will split off all of the commands into their own class, which would work better, and I would suggest it.
The issue with your code looks like a NPE in your class main on line 43 (its in your onEnable() method)