After migrating to AndroidX YoutubeAndroidPlayerAPi getting errors inside the YouTubePlayerSupportFragment
showing
required androidx.fragment.app.Fragment
As you migrate you project to androidx. So you need to verify that all the imports of used libraries are mounted to androidx.
If you go to YouTubePlayerSupportFragment' class and check the import class ofFragment`.
Just remove that import and import the fragment with androidx.fragment.app.Fragment
It will resolve your issue. It may cause same on other files as well, repeat the same steps.
Edit your import
import android.support.v4.app.Fragment;
replace with
import androidx.fragment.app.Fragment
Related
Im following headfirst methodology to learn to code in androidstudio.
they provide some code for building a simple navigation drawer app.
in order to be compatible with previous android version, they advise to import :
import android.content.Intent;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
but in my last version of android studio this doesnt work : some of them are greyed and alt+enter does not import the correct library when i put the java code provided by my methodology.
so i replaced a few imports with the newer versions. for example :
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.ActionBarDrawerToggle ;
import android.widget.Toolbar;
however, i did not find anything for to import "NavigationView" and com.google.android.material.navigation.NavigationV iew is grayed when i try to import it.
So my question is basic: how do i know which lib to import when android studio does not suggest anything with alt+enter and when the libraries have evolved? the question could be asked for many programs i guess ..is there a standard methodology to upgrade the code?
You first need to include your dependencies in your build.gradle (app) file.
For example, your NavigationView is a part of Google's Material library. This library does not come included in Android SDK when you create the project and therefore you need to add the library under 'dependencies' in your build.gradle (app) file in order to use it:
dependencies {
implementation 'com.google.android.material:material:1.3.0-alpha01'
}
This way, upon the build of the project, Gradle will download the library and include it in your project so you can use the Material components. You can usually find the gradle dependency you need to include with a quick Google search.
Another thing to note is that the legacy support libraries have been replaced with AndroidX as you can read here:
https://developer.android.com/topic/libraries/support-library
https://developer.android.com/jetpack/androidx
And you can find the full list of AndroidX support libraries in here:
https://developer.android.com/jetpack/androidx/explorer
I'm learning Notifications.
There is a sample project user-interface-samples, I find many files in the project exists Code A.
But the artical tell me "NotificationCompat is obsolete", please see Image A
1: Code A use latest androidx namesapce, why is it obsolete?
2: Is there a sample project about Notifications based AndroidX which is part of Jetpack.
Code A
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompat.BigTextStyle;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.content.ContextCompat;
Image A
You're looking at the documentation for android.support.v4.app.NotificationCompat, part of the pre-AndroidX Support Libraries. That class is deprecated, but you aren't using that version, so the documentation there is irrelevant.
The AndroidX equivalent, androidx.core.app.NotificationCompat is not deprecated.
I'm using Android Studio and build as "Generate Signed APK...". And I faced the error, "Unused import statement" like following.
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity; // <- specified as unused ERROR
import android.support.v4.app.FragmentManager; // <- specified as unused ERROR
import android.support.v4.view.ViewPager; // <- specified as unused ERROR
import android.util.Log;
public class Main extends FragmentActivity {
...
}
But I can easily see FragmentActivity is used in code. How can I fix it? This error happens all over my codes...
This is because you have "Optimize imports on the fly" enabled, which automatically removes unused imports. You likely also have "Add unambiguous imports on the fly" selected, which automatically adds imports you need. The solution is to write the code first, and watch your imports be added automatically, and manually add any ambiguous ones, as they become needed.
https://www.jetbrains.com/idea/help/creating-and-optimizing-imports.html?search=optim
In the event this does not work for you, or if you simply prefer to enter your own import statements, then simply disable the features in settings > Editor > Auto Import.
When I updated the android studio to 3.3.1 I go this error.
Solved it by updating the libraries and compileSdkVersion to the latest version that is 27. Hope it will help someone else.
I meet the problem in the Android studio 3.2.1. Invalidate and delete ./idea does not work. It disappear when I upgrade 3.4.1.
I have imported a project from a book on Android development and I am currently getting warnings icons appearing next to a number of imports at the start of my project. When I hover over the warning icon the message that appears is as follows...
"The import java.io.IOException is never used"
I received these warning before on another project and when I imported a the necessary library the warning icons disappeared. My problem is that I do not know which library to import to resolve the warning symbol next to the following statements in my .java file...
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.util.GregorianCalendar;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
I assume you're using Eclipse. Go to Source -> Organize Imports. The unnecessary imports should automatically be removed and only the ones really needed should remain.
Remove
import java.io.IOException;
this is not a problem and you don''t need to import any library to fix this.
All you need to do is "organize imports"
Option 1: right click in the editor ->Source->Organize Imports
Option 2: press [Ctrl]+[Shift]+o
"The import java.io.IOException is never used"
This warning means that you have imported a class java.io.IOException that you are not using in your code. This is not a compiling error so you don't have to fix it in order to run correctly your project.
Anyway if you wanna make the warning vanish there are many ways.The fastest one is to just eliminate this line. If you are using Eclipse and you have many warnings like this then the fastest fix is to put the mouse cursor over the yellow underlined text and wait the open of the quick-fix panel of Eclipse. In this panel you can chose both "remove unused import" or "Organize import". Both this system will remove all your unused import. There is also a third option: "#Suppress warnings". In this case you shouldn't use this option because it will only hide the warning not solving the problem.
Eclipse quick-fix is a powerful feature, using it will fast your code writing a lot so you should start practice it ^^
This kind of error are quiet often in project because many programmers doesn't care a lot for the "unused import warnings" and through the code change they forget to remove useless import
Ok i'm just starting to get into Android programming now, and I'm following the android "TabActivity" tutorial: http://developer.android.com/reference/android/app/TabActivity.html.
Everythings working but it can't seem to find some of the support classes, see the code below that is generating the errors.
mTabManager.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class,null);
For FragmentStackSupport/LoaderCursorSupport/LoaderCustomSupport/LoaderThrottleSupport, it says for all of them cannot be resolved to a type. I've added the latest support library to a folder in the root directory named "libs" and also coppied it into "C:/Eclipse/v4/" directory. My import files are:
import java.util.HashMap;
import android.R;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.TabHost;
import cowdawg.hello_tab.namespace.R.layout;
import cowdawg.hello_tab.namespace.R.id;
Could someone please offer me some advice on how to solve this, thanks :).
It's probably because the following classes are not part of the standard Android API (or the support library), but only exist in the support demos sample code for demonstration purposes:
FragmentStackSupport.CountingFragment
LoaderCursorSupport.CursorLoaderListFragment
LoaderCustomSupport.AppListFragment
LoaderThrottleSupport.ThrottledLoaderListFragment
You will need to add these classes to your own project in order to be able to use them. Here you can find the source files under the subsection 'Files'.
FragmentStackSupport
LoaderCursorSupport
LoaderCustomSupport
LoaderThrottleSupport
On Eclipse IDE: Select your project and then right click on the project -> Android Tools -> Add Support Library.
Required support library will be added on your project build path. You will found this library jar under Java Build Path -> Libraries tab -> Android Dependencies.
Enjoy exploring!
Have you added the library to your build path? Right click on the jar in eclipse -> Build Path -> Add to Build Path.
Try adding by right clicking on the project and opening properties window
Instead of these missing classes you can create your own by subclassing Fragment class (or its subclasses like DialogFragment, ListFragment etc). More info is provided by Android here.