• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

IllegalStateException Android Studio

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First post here and completely new to programming (pretty much)
Using a book for beginners that uses Java in Android studio.

We're supposed to change the blank app (nothing else has been changed, so when run, it would open the app which would just be a blank screen) to make it run in full screen.
So this is the original manifests folder code right out the box:



Which obviously works just fine with no errors. But then we've to add 2 lines of code, lines 13 and 14



Now in the book, the whole manifests code isn't shown....we're just told to add those 2 lines. But I get an error....when I run the code with an emulator, it force closes and I get this error:



So yeah, I'm stuck on the first part of chapter 1. I have been trying to find solutions online, but since I'm a beginner, I didn't really understand the solutions. Any help would be much appreciated. Thanks
 
Marshal
Posts: 64654
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I don't know any Android, but shall keep only your question here because we don't like the same question in several places.
 
Chris Macdonald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

I don't know any Android, but shall keep only your question here because we don't like the same question in several places.



Oh ok. No problem! Wasn't sure about the rules
 
Master Rancher
Posts: 451
6
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer to your question lies in this:   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

If you look at the AppCompat you will know.  You should check the library you are using because there are different activity classes depending on the library.  Make sure that the libraries and classes you are using are the same as in the book.

Basically, AppCompat  means you are using the support library so the activity class you are using comes from that.  The error is telling you that you need to use a theme for that kind of activity.
 
Chris Macdonald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Al Hobbs wrote:The answer to your question lies in this:   Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

If you look at the AppCompat you will know.  You should check the library you are using because there are different activity classes depending on the library.  Make sure that the libraries and classes you are using are the same as in the book.

Basically, AppCompat  means you are using the support library so the activity class you are using comes from that.  The error is telling you that you need to use a theme for that kind of activity.



Thank you! The problem was with android:theme="@style/AppTheme"
Had to change that to AppCompat and it works now.
Much appreciated. I can sleep soundly now knowing I'll be able to carry on with this book tomorrow
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!