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'
}
Related
I'm trying to go through the google tutorial on building good ap architecture. I'm using java 8 and SDK 26.
Here is the code I have so far :
package test.me;
import android.app.Fragment;
import android.arch.lifecycle.ViewModel;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
public class ChronoFragment extends Fragment {
private ViewModel my_model;
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
my_model = ViewModelProviders.of(this).get(ViewModel.class); // <-- error on this
// and so on
}
}
The trouble is that so far, the SDK returns the following error:
Cannot resolve the method 'of(test.me.ChronoFragment)'.
I don't understand this since
ChronoFragment is of type Fragment
The method ViewModelProviders#of(Fragment) does exist and is accessible via the sdk.
Any idea on what I'm doing wrong ?
Architecture Components uses the appcompat Fragment from the support library rather than the native one. Try changing your import for Fragment to
import android.support.v4.app.Fragment;
For historical reasons, there are two different Fragment classes. They have the same functionality but exist in two different packages. For details, see Why are there two Fragment classes in Android?
As of Feb 6, 2019:
Now there is a third Fragment class. If you are using the new AndroidX libraries, then do
import androidx.fragment.app.Fragment;
Be sure you use the correct Fragment class which is consistent with the rest of your dependencies.
I have had the same problem, what the google documentation does not tell you is that you need to add the following dependencies in to your Build Gradle file and then "Sync"
implementation "android.arch.lifecycle:extensions:1.1.1"
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
I have faced the same problem while using Android X libraries and used following to resolved.
Gradle dependencies for Android X:
implementation "androidx.lifecycle:lifecycle-extensions:2.1.0-alpha04"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.1.0-alpha04"`
Import:
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModel;
Reference - https://developer.android.com/jetpack/androidx/migrate
I have had the same problem, android studio automatically imported android.support.v4.app.Fragment; but I was using androidX. if your situation is same, you must use
androidX imports everywhere
import androidx.fragment.app.Fragment;
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 import the BigDecimalMath class into my current project. I created a new library by going to Tools -> Libraries -> New Library. I called the library BigDecimalMath, as you can see below. I added a new JAR/Folder and then selected the download from Cornell's website, here. Direct download.
I'm unsure of how to import it into my class now. This library is part of my current project. I've tried import org.nevec.rjm and some other things, but I think I'm doing something wrong. Any advice appreciated. Thanks!
You appear to have a source version of that library. Your window displays a jar containing org.nevec.rjm.BigDecimalMath.java. I think you need to download a binary version of the jar and add that to your class-path. Then you would import that one class with,
import org.nevec.rjm.BigDecimalMath;
or the entire package with,
import org.nevec.rjm.*;
Alternatively, you might be able to build the library from your src jar.
I am trying to import the following class for an android project
import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;
But I get an error "The type android.support.v7.internal.widget.AdapterViewICS is not visible" All my other imports are working fine thus far and I am using the android ADT bundle downloaded directly from google.
I've got a similar problem after a git merge and, probably, Eclipse being crazy about packages auto-import.
Just replace
import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;
with
import android.widget.AdapterView.OnItemClickListener;
The original AdapterView is supported since API Level 1 thus you will not break the app on old devices.
replace the import statement"import android.support.v7.internal.widget.AdapterViewICS.OnItemClickListener;" with "import android.widget.AdapterView.OnItemClickListener;",sometimes Eclipse cannot find the right packages for auto import.
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.