I am sorry for the very basic question but I feel truly lost here. What I am trying to do is to compile and run this code:
package com.gc.android.market.api;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.io.InputStream;
import com.gc.android.market.api.MarketSession;
import com.gc.android.market.api.MarketSession.Callback;
import com.gc.android.market.api.model.Market.AppType;
import com.gc.android.market.api.model.Market.AppsRequest;
import com.gc.android.market.api.model.Market.AppsRequest.OrderType;
import com.gc.android.market.api.model.Market.AppsRequest.ViewType;
import com.gc.android.market.api.model.Market.AppsResponse;
import com.gc.android.market.api.model.Market.CommentsRequest;
import com.gc.android.market.api.model.Market.GetAssetResponse.InstallAsset;
import com.gc.android.market.api.model.Market.GetImageRequest;
import com.gc.android.market.api.model.Market.GetImageResponse;
import com.gc.android.market.api.model.Market.ResponseContext;
import com.gc.android.market.api.model.Market.GetImageRequest.AppImageUsage;
public class Fetcher
{
public static void main(String[] args) {
MarketSession session = new MarketSession(true);
System.out.println("Login:");
}
}
I am following the instructions from here: https://code.google.com/p/android-market-api/wiki/HowDownloadApps
The import and package lines I got from here: https://code.google.com/p/android-market-api/source/browse/trunk/AndroidMarketApi/src/com/gc/android/market/api/Main.java
I am doing this on OS X. In my current directory I have three files:
Fetcher.java (the code above)
AndroidMarketApi.jar
protobuf-java-2.2.0.jar
I compile using this command:
$ javac -classpath ".:/Users/ephracis/fetcher/*" Fetcher.java
I then try to run:
$ java Fetcher
Exception in thread "main" java.lang.NoClassDefFoundError: Fetcher (wrong name: com/gc/android/market/api/Fetcher)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
$ java com.gc.android.market.api.Fetcher
Exception in thread "main" java.lang.NoClassDefFoundError: com/gc/android/market/api/Fetcher
Caused by: java.lang.ClassNotFoundException: com.gc.android.market.api.Fetcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I've also tried to add the classpath to the java command but it doesn't change anything.
To execute you need the fully qualified class name (package + class name). Try:
java -classpath ".:/Users/ephracis/fetcher/*" com.gc.android.market.api.Fetcher
Also, you still need to include the appropriate classes/jars on the classpath.
Related
I got this error when i'm trying to run my code by the statement "LauncherImpl".
Has anyone an idea how to fix it?
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.IllegalAccessError: class application.view1controller (in unnamed module #0x3fb6a447) cannot access class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.application to unnamed module #0x3fb6a447
at application.view1controller.main(view1controller.java:24)
... 11 more
Exception running application application.view1controller
package application;
import com.sun.javafx.application.LauncherImpl;
import javafx.application.Application;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class view1controller extends Application {
public void start(Stage view1) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/application/view1.fxml"));
Scene scene = new Scene(root);
view1.setScene(scene);
view1.show();
}
public static void main(String[] args) {
LauncherImpl.launchApplication(view1controller.class, SplashScreen.class, args);
}
VM Arguments:
--module-path "D:\Fabian Boni\Documents\eclipse workspace\javafx-sdk-11.0.2\lib" --add-modules
javafx.controls,javafx.fxml,javafx.base,javafx.graphics
I have problem.
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class qq {
public static void main(String[] args) throws UnsupportedEncodingException, IOException {
HttpClient httpclient = new DefaultHttpClient();
// HttpPost httppost = new HttpPost("http://192.168.0.102/uploadtest/upload_photo");
System.out.println("aaaa");
}
}
File manifest.mf:
Manifest-version: 1.0
Main-Class: qq
OS debian 8
java version:
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
And:
javac -cp ./lib/httpclient-4.2.5.jar:./lib/httpcore-4.4.5.jar:./lib/httpmime-4.2.5.jar:./lib/commons-logging-1.2.jar qq.java
jar cfm test.jar manifest.mf qq.class
Its ok, no error, exit code - 0.
I try:
# java -jar test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
at qq.main(qq.java:18)
Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.client.DefaultHttpClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
How to fix this ?
I advise you to use Maven or Gradle because the depandances are loaded automatically.
Maven:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
Gradle:
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.1'
I am trying to use 2 Java defined classes in python using jython 2.7.0 but after i ran my script it throws a java.lang.NoClassDefFoundError
Those are my 2 Java classes:
Hello.java
package hello;
public class Hello {
public void printMsg(){
System.out.println("check out this cool message");
}
}
Hello2.java
package hello;
public class Hello2 {
public void printHelloMsg(){
Hello msg = new Hello();
msg.printMsg();
}
}
I compiled them with:
hello$ javac Hello.java Hello2.java
Then created a jar file with:
hello$ jar cf hello-jar.jar *.class
And my python script that is supposed to use the Hello2 class, which uses Hello class:
hello.py
import Hello2
h = Hello2()
h.printHelloMsg()
After i ran my script with jython using:
hello$ jython -J-cp ./hello-jar.jar hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
import Hello2
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.python.core.Py.loadAndInitClass(Py.java:991)
at org.python.core.Py.findClassInternal(Py.java:926)
at org.python.core.Py.findClassEx(Py.java:977)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)
at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:33)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)
at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:134)
at org.python.core.PyObject.__findattr__(PyObject.java:946)
at org.python.core.packagecache.PackageManager.lookupName(PackageManager.java:141)
at org.python.core.JavaImporter.find_module(JavaImporter.java:40)
at org.python.core.JavaImporter.find_module(JavaImporter.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Hello2 (wrong name: hello/Hello2)
What could possibly be the problem here?
Thanks in advance
The problem is in the file hello.py. The import statement is incorrect; it should be:
from hello import Hello2
instead of
import Hello2
I am trying to test java methods within a multiple package project that has numerous imports. It works fine until it gets to the javax imports. Tnen it complains that it cannot find the class definition for this import. Do I need to explicitly import a jar even though it was part of the maven dependencies when I complied the jars that this project is using?
This is the declarations section of my code package
package com.fietrade.swtf.swreconcilation.beans;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIComponent;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import javax.faces.validator.ValidatorException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.xml.sax.SAXException;
import com.fietrade.swtf.persistance.factories.DBMgrFactory;
import com.fietrade.swtf.persistance.factories.ReconciliationDBMgr;
import com.fietrade.swtf.persistance.swapswire.Reconciliation;
public class ReconciliationEditor {
And this is the error:
__EXCEPTION__:java.lang.NoClassDefFoundError: javax/faces/validator/ValidatorException
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_40]
at java.lang.Class.forName(Class.java:190) [rt.jar:1.7.0_40]
at fitnesse.slim.SlimExecutionContext.getClass(SlimExecutionContext.java:139) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimExecutionContext.searchPathsForClass(SlimExecutionContext.java:129) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimExecutionContext.createInstanceOfConstructor(SlimExecutionContext.java:100) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimExecutionContext.create(SlimExecutionContext.java:42) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.StatementExecutor.create(StatementExecutor.java:75) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.instructions.MakeInstruction.executeInternal(MakeInstruction.java:26) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.instructions.Instruction.execute(Instruction.java:30) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.ListExecutor$Executive.executeStatement(ListExecutor.java:50) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.ListExecutor$Executive.executeStatements(ListExecutor.java:44) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.ListExecutor.execute(ListExecutor.java:84) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimServer.executeInstructions(SlimServer.java:106) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimServer.processTheInstructions(SlimServer.java:93) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimServer.processOneSetOfInstructions(SlimServer.java:68) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimServer.tryProcessInstructions(SlimServer.java:54) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimServer.serve(SlimServer.java:40) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimService.handle(SlimService.java:164) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimService.acceptOne(SlimService.java:172) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimService.accept(SlimService.java:134) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimService.startWithFactory(SlimService.java:65) [fitnesse-standalone-20140903.jar]
at fitnesse.slim.SlimService.main(SlimService.java:51) [fitnesse-standalone-20140903.jar]
Caused by: java.lang.ClassNotFoundException: javax.faces.validator.ValidatorException
Can someone explain what this error is and how to resolve it?
Thanks
Basically it says It is not able to find a dependancy for your project to work ..
include jsf-api
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
Add this to your project and error will be resolved.
I've been trying to send information from Java to Java script using the JSObject but i keep receiving a java.lang.ClassNotFoundException: com.sun.deploy.appcontext.AppContext exception i'm using netbeans 7.1.
Here is the full stack trace
java.lang.NoClassDefFoundError: com/sun/deploy/appcontext/AppContext
at MapTest.MapApplet.init(MapApplet.java:23)
at sun.applet.AppletPanel.run(AppletPanel.java:434)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: com.sun.deploy.appcontext.AppContext
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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)
... 3 more
It is referring to this line of code
win = JSObject.getWindow(this);
These are all my imports
import netscape.javascript.JSObject;
import java.lang.*;
import java.applet.*;
import java.awt.Graphics;
I really need help with this can't seem to find solutions anywhere.
Thanks.
I came across a similar error and was able to solve it by adding deploy.jar found in the local Java install to the project build path. Not sure how to do this in netbeans but for others using maven you can try adding the folowing dependency:
<dependency>
<groupId>sun</groupId>
<artifactId>deploy</artifactId>
<version>7.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/deploy.jar</systemPath>
</dependency>