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.
Related
I am attempting to generate a JavaDoc for my project. To do so, I use Tools > Generate JavaDoc. I check Whole Project and set the output directory. It starts to work then returns with
error: package android.content does not exist
import android.content.Context;
Along with a bunch of other package does not exist errors and
cannot access ViewGroup
public class MainMenu extends AppCompatActivity {
^
class file for android.view.ViewGroup not found
Thus far I haven't been able to find any sort of solution. My project builds and runs fine on both the emulator and actual devices. Any thoughts? Thanks!
I was able to find a work around. I loaded my project in intelliJ IDEA, and while it still showed those errors, it still was able to generate the javadoc that correctly contains all the classes and methods needed.
Here is my directory structure within the "java" folder,
The problem is in my MainActivity file when I write.
import api.gitapi;
import model.gitmodel;
I get a warning message saying "Unused Import"
In my MainActivity file, I get an error on line,
gitapi git = restAdapter.create(gitapi.class);
and,
public void success(gitmodel gitmodel, Response response) {}
saying that the symbol gitapi and gitmodel cannot be resolved. I have tried "Invalidate caches/restart" but the problem still exists.
Any help is appreciated, thanks in advance!
PS: If it helps, I'm using this tutorial
You have placed the gitapi and gitmodel classes into a test source folder, meaning that they are available to be imported by other classes in the test folder, but not in the main folder (where your activity lives). Create those classes in the main source folder and your activity will be able to import and reference them.
just need to refract the classes into the package containing MainActivity.class and it might solve your problem and you will get the result what you want.
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'm trying to do the demo for the new Cast SDK (for using Chromecast), but I'm having trouble. I downloaded a demo for Android, and I'm getting errors in my project when trying to import anything from android.support.v7 library.
If I try to import from android.support.v4 or android.support.v13, things show up, but nothing shows up when I try to import from android.support.v7. It seems as if I don't have these files, but when I open the Android SDK Manager, it seems that I have most things installed (Android 3.0 API 11 and above).
Does anyone know why I might be missing this, or how to get it up and running?
Here are the files that I need to import for my demo:
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.MediaRouteActionProvider;
import android.support.v7.media.MediaRouteSelector;
import android.support.v7.media.MediaRouter;
import android.support.v7.media.MediaRouter.RouteInfo;
If you wants to integrate actionbar below android sdk 3.x use given link reference:
Android Demo:
http://developer.android.com/tools/support-library/features.html
"uses-sdk
android:minSdkVersion="7"
Support Library classes that provide support for android sdk 2.x and above.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("ActionBar Support Demo");
}
}
http://www.coderzheaven.com/tag/android-support-v7-appcompat-jar/
There are multiple v7 libraries: appcompat, mediarouter and gridlayout. Follow the steps here to import and set them up (use Android Libraries with Resources); you need to install appcompat first and then mediarouter and make sure the mediarouter library lists appcompat as part of its dependency.
If you have already downloaded libraries, it will be present in android-sdk
at following location.
android-sdk\extras\android\support\v7\mediarouter\libs\android-support-v7-mediarouter.jar
similarly include other jars as well from follwing folder.
android-sdk\extras\android\support\v7
add these jars in your android project inside libs folder.
I fixed the import of MediaRouter by adding this line into the dependencies inside the build.gradle file:
compile 'com.android.support:mediarouter-v7:21.0.3'
Android Studio imports that as a library so there won't be any troubles with the resources at all.
You need to download and install Android Support Repository using the SDK Manager in Android Studio.
After that add the dependencies inside the build.gradle file as shown below
dependencies {
'compile com.android.support:mediarouter-v7:25.0.0'
}
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.