How to run plain old JUnit tests in Android Studio - java

I want to test some regular classes and methods that have nothing to do with Android, with JUnit in Android Studio 1.1.0
In the test package I have the following class:
public class ParametrizedStaticMapsRequestTest extends TestCase {
#SmallTest
public void testBuildingStaticMapsRequestURL() {
System.out.println("asd");
}
}
But when I try to run it, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:116)
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more
I read on the internet that this happens because Im trying to run it as an Android Test. I want to run it as a plain old JUnit test, like I was able to do in Eclipse. What do I do?

Here's one way to do it using an official but experimental functionality: link

Related

Can't run COMPSs application. ClassNotFoundException

I am learning COMPSs. Until now, everything has been working really well, but I only executed the examples given in the manual.
Now that I want to run my own test application, I can't get it to work. I must be missing something, but I can't see what I am doing wrong.
My application is called App, and has the main class App, and the interface in another class called AppItf. When I try to run it using runcompss:
runcompss -d --classpath=$PWD/App.jar App
I get the following message:
Using default location for project file:
/opt/COMPSs/Runtime/scripts/user/../../configuration/xml/projects/project.xml
Using default location for resources file:
/opt/COMPSs/Runtime/scripts/user/../../configuration/xml/resources/resources.xml
----------------- Executing App --------------------------
[Loader] - There was an error when loading or executing your
application. java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at integratedtoolkit.loader.ITAppLoader.load(ITAppLoader.java:54)
at integratedtoolkit.loader.ITAppLoader.main(ITAppLoader.java:84) Caused
by: java.lang.ClassNotFoundException: AppItf
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at integratedtoolkit.loader.CustomLoader.loadClass(CustomLoader.java:56)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:195)
at integratedtoolkit.loader.total.ITAppModifier.modify(ITAppModifier.java:46)
... 6 more
Error running application
Can somebody help me find what I am doing wrong?
Thank you in advance!
In the runcompss command you have to specify the fully qualified domain name of the class. So, if this class has a package you have to add the package to the class name. It is currently missing.

Developing GATE plugin in Java: org/apache/log4j/Logger error

I'm a Java beginner and have a question similar to the ones here: Java, How to add library files in netbeans?
and Caused By: java.lang.NoClassDefFoundError: org/apache/log4j/Logger
I followed the answers given there, which were very good, but I still cannot solve my problem.
I'm developing a plugin for GATE in Java using NetBeans 7.
I have written this first, trial code:
public class LoadGateDoc {
public static void main(String[] args) throws Exception {
Gate.init(); // prepare the library
Factory.newDocument("This is a document"); // create a new doc
}
}
But when I compile, I get the following error messages:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at gate.Gate.<clinit>(Gate.java:83)
at loadgatedoc.LoadGateDoc.main(LoadGateDoc.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 2 more
Java Result: 1
I have added the "commons-logging" as well as the "org/apache/log4j/Logger" libraries to the properties of my NetBeans project, but this doesn't help, I get the same error messages anyway.
Can you please help me out?

Java using ZMQ (and Eve EMDR)

I'm trying to connect to eve EMDR using ZMQ in java, and I just get this error, any ideas?
http://eve-market-data-relay.readthedocs.org/en/latest/using.html#java
Code: https://gist.github.com/Sparcster/d140654cd157c73e0957
> Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Multimap
at zmq.Reaper.<init>(Reaper.java:49)
at zmq.Ctx.create_socket(Ctx.java:270)
at org.zeromq.ZMQ$Socket.<init>(ZMQ.java:362)
at org.zeromq.ZMQ$Context.socket(ZMQ.java:311)
at spacevac.Spacevac.main(Spacevac.java:18)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Multimap
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 5 more
Java Result: 1
Also: I'm using JeroMQ instead of JZMQ.
This sounds like it is related to the new use of the Guava library. Adding guava to the dependency pulls and the eclass path in the maven.xml file fixes these errors, according to (1) https://github.com/zeromq/jeromq/issues/174 and (2) https://github.com/zeromq/jeromq/issues/176. You also may have a stale Ant build.xml, and might need to blow that away and regenerate it, if that is what you are using.

What does this java error mean java.lang.NoClassDefFoundError: org/apache/mahout/cf/taste/impl/model/jdbc/ConnectionPoolDataSource

I've been trying to run Mahout on a amazon ec2 instance. I keep getting an error when the script executes.
my config script is like this
CLASSPATH=recommender/recommender.jar:async/async-command.jar:async/lib/:./.m2/repository/org/apache/mahout/mahout-core/0.6/
java.lang.NoClassDefFoundError: org/apache/mahout/cf/taste/impl/model/jdbc/ConnectionPoolDataSource
at org.drupal.project.recommender.RunRecommender$AlgorithmImpl.initDataModel(RunRecommender.java:671)
at org.drupal.project.recommender.RunRecommender$AlgorithmImpl.run(RunRecommender.java:954)
at org.drupal.project.recommender.RunRecommender.run(RunRecommender.java:435)
at org.drupal.project.async_command.Druplet.runSerial(Druplet.java:379)
at org.drupal.project.async_command.Druplet.run(Druplet.java:284)
at org.drupal.project.async_command.CommandLineLauncher.handleExecutables(CommandLineLauncher.java:107)
at org.drupal.project.async_command.CommandLineLauncher.launch(CommandLineLauncher.java:66)
at org.drupal.project.recommender.RecommenderApp.main(RecommenderApp.java:37)
Caused by: java.lang.ClassNotFoundException: org.apache.mahout.cf.taste.impl.model.jdbc.ConnectionPoolDataSource
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
I understand that this means that some class was not found, I have no idea how to fix it
On you amazon box you need to ensure that this path :./.m2/repository/org/apache/mahout/mahout-core/0.6/
exists and unless you are reading class files from this directory, then you modify this line to include that jar file name
e.g.
:./.m2/repository/org/apache/mahout/mahout-core/0.6/mahout_core.0.6.jar

Unable to run Scala-Neo4j project from command line [duplicate]

This question already has answers here:
Building JAR that includes all its dependencies
(5 answers)
Closed 8 years ago.
I developed a Java project in which I wrote some Scala classes and some Java classes. I used Scala-Neo4j wrapper in the project to write Scala functions for inserting and retrieval of Neo4j nodes. I also wrote Thrift services in java in the project as I need to call these Scala functions from Php. Finally I extracted a jar file using Eclipse and I tried to run it from the command line and I got the following Exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/neo4j/scala/Neo4jWrapper
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 dum.Sad.main(Sad.scala)
at dum.ScalaRunner.main(ScalaRunner.java:7)
Caused by: java.lang.ClassNotFoundException: org.neo4j.scala.Neo4jWrapper
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)
... 14 more
It works completely fine when I run the project from Eclipse. But, while running the jar file which I extracted from the project I get the Exception above. Where did i go wrong?
It seems your are not setting the classpath up properly. Try this:
scala -cp ./where/is/Neo4jWrapper/jar YourClass
Of course, replace ./where/is/Neo4jWrapper/jar with the path to the .jar. Notice that if you need to point to more than one jar or class directory you need to separate them with : if on Linux/Mac or ; if in Windows. And avoid spaces in the classpath.

Categories

Resources