I have put the rest-assured-2.2.0.jar in my Eclipse workspace (for an Android app) and added it to the buildpath of the project as referenced library. Then I imported:
import com.jayway.restassured.RestAssured;
import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
But still if I do RestAssured.given(); I get
Caused by: java.lang.NoClassDefFoundError: com.jayway.restassured.internal.ResponseParserRegistrar
If I look inside the jar file I can find a ResponseParserRegistrar.class file on the right place, so it does exist.
If I try to import it it does not complain:
import com.jayway.restassured.internal.ResponseParserRegistrar;
But it still gives the error.
What did I forget or do wrong?
EDIT
Now I've created a blank new Android app with the following MainActivity:
package com.example.testrestassured;
import com.example.testrestassured.R;
import android.app.Activity;
import android.os.Bundle;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.RestAssured.*;
import com.jayway.restassured.internal.ResponseParserRegistrar;
import com.jayway.restassured.matcher.RestAssuredMatchers.*;
public class MainActivity extends Activity{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
RestAssured.given();
}
}
The project has only one referenced library: rest-assured-2.2.0.jar (correct spelling).
Still I get the same problem
E/AndroidRuntime(13142): Caused by: java.lang.NoClassDefFoundError: com.jayway.restassured.internal.ResponseParserRegistrar
EDIT
Changing to rest-assured-2.3.0.jar (new version) and adding json-schema-validator-2.3.0.jar and it's big list of dependencies did not fix it either. I've tried to find the runtime classpath, but I can't find it in the menus of ADT.
Make sure that you don't have more than one version of the jar. This is very common in projects using Maven, when parent projects have older versions of the libraries.
If you tell us more about your configuration it would be easier to try and find the cause.
Look NoClassDefFoundError is thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
Now in above as you are having MAVEN project it might be you have not added dependency of your rest-assured-2.2.0.jar in pom.xml.
And if you're building either Eclipse RCP or Eclipse plugin.
If yes, you should put rest-assured-2.2.0.jar under plugin dependencies. Go to plugin.xml, Runtime and put rest-assured-2.2.0.jar in the classpath.
Moreover as a cross-check please check the spelling name you used everywhere is same.
Related
I am working on a Java fx application and I need to import some libraries from com.google.maps.
I imported these libraries :
import com.google.maps.GeoApiContext;
import com.google.maps.PlaceDetailsRequest;
import com.google.maps.PlacesApi;
import com.google.maps.QueryAutocompleteRequest;
import com.google.maps.errors.ApiException;
import com.google.maps.model.AddressComponent;
import com.google.maps.model.AddressComponentType;
import com.google.maps.model.AutocompletePrediction;
import com.google.maps.model.PlaceDetails;
The java import statement is a little bit misnamed, it really means alias. import com.google.maps.GeoApiContext; really just means: Any time you find the type GeoApiContext anywhere in this source file, assume I meant to write com.google.maps.GeoApiContext.
Crucially, it does not 'invoke' any code in that class whatsoever, nor does it find or download any dependencies from the internet for you.
You will need to find the jar(s) that provide these classes and put them on the classpath of this project.
It can be as simple as downloading the relevant jar (perhaps com.google.maps-google-maps-services.jar?), put it in a lib dir someplace inside this project, finding that in the package explorer, right clicking it, and selecting 'add to classpath'.
Or, more likely, you want to use gradle or maven to take care of this for you: These tools turn simply mentioning the dependency in a list of libraries you require into automatically finding that on the internet, downloading it, configuring your IDE so that it knows where it is, and using that dependency during build and run steps.
I'm new to java , i tried to use word net for senitment analysis .
when i used class of wordnet , i got the following failure in importing
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.lucene.analysis.en.EnglishMinimalStemmer;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileListener;
import org.apache.stanbol.commons.stanboltools.datafileprovider.DataFileTracker;
import org.apache.stanbol.enhancer.engines.sentiment.api.LexicalCategoryClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.api.SentimentClassifier;
import org.apache.stanbol.enhancer.engines.sentiment.util.WordSentimentDictionary;
import org.apache.stanbol.enhancer.nlp.pos.LexicalCategory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
all the above imports cannot be resolved like org.apache.felix , org.apache.lucene ,org.apache.stanbol,org.osgi
This is because your compiler is not able to find the necessary packages and or libraries that are needed to resolve these imports. These packages must be included in your class path. For example all of the errors regarding
org.apache.felix.scr.annotations.x
can be resolved after downloading the latest .jar from https://mvnrepository.com/artifact/org.apache.felix/org.apache.felix.scr.annotations/1.11.0
Follow these steps to include jar files in your class path.
-
Drag the required jar file from your download directory to the src
directory of your project in eclipse
Right click on the jar file, Select Build Path and then select Add To Build Path option.
A dialogue box will appear asking you to link all files in the jar file, just stick with the defaults and hit OK.
You are done now, all your errors regarding imports will be resolved.
These packages need to be within the compiler's class path.
Another way to say it : the compiler needs to be able to know where to find these files. This imposes several constraints:
these files need to actually exist in your hard drive (whether added manually, or automatically by a dependency manager)
they should be organized in folders that match the parts of the package name
the folder where they are must be within the class path, which can be specified with the 'classpath' compiler option, or in your IDE's options
I have an Android app in which I wanted to use the DB2SimpleDataSource class contained in the db2jcc.jar / db2jcc4.jar file. I wanted to use this class to establish a connection to a DB2 Database, but I noticed a problem with that class.
So I wrote a very simple app which just instantiate a DB2SimpleDataSource class object,in this way:
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.ibm.db2.jcc.DB2SimpleDataSource;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DB2SimpleDataSource dataSource = new DB2SimpleDataSource(); //--->Error!
}
Here's the problem:when I write this code,Eclipse shows no errors about this class,but when i run this app,it shows the following error in logcat:
Could not find class 'com.ibm.db2.jcc.DB2SimpleDataSource' referenced
from method 'com.example.provadb2.MainActivity.onCreate'
Here's the process I used to add the JARs:
Right click on project>Properties
From Java Build Path,in Libraries tab,i clicked "Add External JARs" and pointed to the db2jcc.jar file
In Order and Export tab,i checked db2jcc.jar
I also tried unchecking in the Order and Export tab but nothing happened.
I also tried to use db2jcc4.jar file,without results.
The "funny" thing is that,when I wrote the same code in Java instantiating a DB2SimpleDataSource class object,it worked without errors...Hope i can find some help,thanks.
Your problem is at runtime, not compile time. Create a lib folder, add your external jars. Now click on individual jars and add to build path.
I am not sure why I cannot import the android.support.v7.app.ActionBarActivity class. I looked at and followed the steps described in this question to change the jar file of the project. However in the solution the first step was to delete the jar file that was already there, I however did not have that file. I am not using gradle.
This is code I got from the android tutorial.
package com.example.myapp;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActvity;
public class DisplayMessageActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
}
}
The error that comes up first is
Error:(5, 30) java: package android.support.v7.app does not exist
In the manifest also wrote this line.
<uses-sdk android:minSdkVersion="7"/>
I assume this is okay because I would need to make sure that v7 stuff is supported. As mentioned in the title I am using IntelliJ.
If you are using IntelliJ IDEA and not Android Studio (gradle based), you
should add the library by going to File > Project Structure
then go to your module, tab Dependencies, and add the jar file from there.
Jar files in libs are not automatically added in IntelliJ, you have to manually add them as dependencies.
Add this in build.gradle in dependencies
compile 'com.android.support:appcompat-v7:21.0.0'
I Already read this, this and this before posting my question.
My problem is slightly different.
I'm a beginner in java and I have a jar file that I need to use in my project (I beleive it is called library).
I imported it to my netbean libraries folder using import jar/folder option and I can see content of the library. Unfortunately the class that I need to import is under default package and using import rearrange; (rearrange is name of class) is not working.
To understand how to use this class I decompiled a class file that is importing exact same class and surprisingly it uses import rearrange; to import that class.
I know that I cannot import classes from default package. and my sample class is not using reflection either.
What I'm doing wrong and how can I import this class?
I also know that library (jar file) and also my sample class are compiled with java 1.6 (they didn't use 1.3.x that was allowing this type of import)