Newbie trying to finish the My first App tutorial provided by Google. On the way to this fatal exception I did import a lot of random packages to get rid of \"cannot be reso
In my case I had a layout which was defined for 720p but not defined for default resolutions so it was crashing. Adding that layout file fixed this issue, logcat dont lie.
I deleted 'build' folder in "yourAppName\app" folder
and everything worked fine. If above solution didn't work, try this. build folder will be auto-generate when you build your project again.
You are getting that error because of the following reasons:
In your Gradle build file your app is targeting and compiling with the beta version of Android that is still in development with:
compileSdkVersion 'android-L'
buildToolsVersion '20'
as well as
minSdkVersion 20
targetSdkVersion 20
First thing to note is that this app will not run correctly (at this time) on any device without android-L flashed to it.
The real crux of your issue is in DisplayMessageActivity, it extends via inheritance [ActionBarActivity]:(https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html) this is one of the support library classes for AppCompat.
To fix this, change your min SDK to 10 (or 14 which is ice cream sandwich), your max SDK to 19 (Kit Kat) and un-comment the appcompat-v7 library in your dependencies.
As a side note, when you declare widgets in their respective activities/fragments it's usually good practice to have their scope be outside of any methods:
EditText editText;
Button sendMessageButton;
// Then in your onCreate() method
editText = (EditText) findViewById(R.id.editText);
sendMessageButton = (Button) findViewById(R.id.sendMessageButton);
This helps reduce memory re-allocation and make your code a little more readable. Sometimes you may have to bend the rules a bit but this is the common practice.
Just
Build -> Clean Project
and then
Build -> Rebuild Project
.
That's all.
In my case the issue occurred in Android Studio 4.0. I suppose there was something wrong with Gradle cache.
Unfortunately, neither Invalidate Сaches / Restart
, nor Build -> Clean Project
& Build -> Rebuild Project
didn't help me, so I had to take drastic measures.
Close Android Studio.
Open Terminal and navigate to your project's root directory.
Delete all Gradle modules' build directories, so all modules will be recompiled soon.
find . -wholename "*/build" -exec rm -rf {} \;
But if you have a single module, then just:
rm -rf app/build
Purge Gradle cache. By default, it's located in your home directory.
rm -rf ~/.gradle
Open Android Studio again. It will start to build the project. It will take a long time, since we have just deleted the cache, but the issue should be resolved.