I have tried invalidating the caches and restarting but it still shows up and will not compile and run as it used to before. I tried renaming the class file if i remember correctly and must have changed the name on something that made this how up. It also gives me the same error where findViewById, .oncreate, and setContentView. I migh have also renamed or tried to rename one of the packages because it was examplecom and it wouldnt allow me to upload it.
package com.threedeestone.mike.threedeestone;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.text.DecimalFormat;
public class MainActivity extends ActionBarActivity {
To use the ActionBarActivity or the AppCompatActivity you have to add the appcompat library to your dependencies.
Add in your build.gradle file the last version:
dependencies {
...
compile "com.android.support:appcompat-v7:23.0.0"
}
The version 23.0.0 requires to compile the project with API 23.
Otherwise you can use the 22.2.1.
Also pay attention.
The ActionBarActivity is deprecated. Check the official javadoc.
You should use the AppCompatActivity.
Check this blog where explains the changes on the Library.
ActionBarActivity is deprecated, you should use AppCompatActivity instead and make a clear project and try it out.
public class MainActivity extends AppCompatActivity {
If the issue still it could be that in your gradle.app you don't have added this line of code
compile 'com.android.support:appcompat-v7:22.1.1'
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
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
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 want to make a login with Google+ login button like this Tutorial
I have copied the codes, set google_play_services libraries, added package name and SHA1 key in google api console, but there are some import errors :
This import is not an error :
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.plus.model.people.Person;
But this import an error (cannot be resolved) :
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.plus.Plus;
Anybody have a solution ?
Add this in yourbuild.gradle(app) inside dependency
compile 'com.google.android.gms:play-services:8.1.0'
[Solved]
I try to download new version of google-play-services library and import error is gone.
So, always update/download newest version of google-play-services library..
You need to add the dependency to your app.
Instructions for eclipse here
http://developer.android.com/google/play-services/setup.html
You can also do this by right clicking on your app (if you're using Android Studio) selecting Open Module Settings, going to the dependency tab. Then Clicking the "plus" at the lower left, select library dependency, then find play-services
I was trying to select min sdk version to 11. After I finish creating the project, the main activity still shows I am importing v7 ActionBarActivity:
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
...
Did I configure something wrong?
Thanks
Open your build.gradle file and make sure that minSdkVersion is set to 11.
Click the Sync Gradle Files button on the toolbar to the left of the SDK manager
the Gradle files will now be automatically re-imported
Clean and Rebuild your project
For those using Android Studio 0.8.6 and having the same issue while following Google's tutorials, what worked for me was to add this line under "dependecies" in your module build.gradle file:
dependencies {
compile 'com.android.support:appcompat-v7:20.0.0'
}
it worked for me!
:)
No, android studio import it automatically because there are some features that worked since version 14.
For example: when you set the actionbar in your XML document and you want to hide / show some item you use "android:showAsAction" attribute, but the compiler generates an error, because that works only on version 14 and later.
So, the compiler tells you that you have to change it in "yourapp:showAsAction" (because you declared to support version 11) where "yourapp" is a namespace that you've imported in your xml file:
xmlns:yourapp="http://schemas.android.com/apk/res-auto
Remember that "yourapp" can be every name you want! Well, now if you test your app you find out that show / hide functionality doesn't work properly, and this is because your activity doesn't extends ActionBarActivity. This is why androidStudio automatically extends ActionBarActivity when you declare a minSdk of 11.
Hope this post was useful, bye!