Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPhilip Harris
4,837 PointsAndroid Virtual Device keeps crashing
every time i run the virtual device it tells me it has unexpectedly stopped working
here is my code
package com.example.crystalball;
import android.graphics.drawable.AnimationDrawable; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
private CrystalBall mCrystalBall = new CrystalBall();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our view variables and assign them views from the layout file
final TextView answerLable = (TextView) findViewById(R.id.textView1);
Button getAnswerButton = (Button) findViewById(R.id.button1);
getAnswerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String answer = mCrystalBall.getAnAnswer();
//Update Label with our new Dynamic answer
answerLable.setText(answer);
animateCrystalBall();
}
});
}
private void animateCrystalBall() {
ImageView crystalBallImage = (ImageView) findViewById(R.id.imageView1);
crystalBallImage.setImageResource(R.drawable.ball_animation);
AnimationDrawable ballAnimation = (AnimationDrawable) crystalBallImage.getDrawable();
if (ballAnimation.isRunning()){
ballAnimation.stop();
}
ballAnimation.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
2 Answers
Gunjeet Hattar
14,483 PointsThe two lines go here, the second style section i.e. the application theme
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
Philip Harris
4,837 PointsTY TY TY you rock
Gunjeet Hattar
14,483 PointsGlad it worked for you. See you around :)
Gunjeet Hattar
14,483 PointsThe error relates to java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
The video in treehouse uses the Theme called ** Theme.Black.NoTitleBar.Fullscreen ** . Are you using this?
If yes, then the new android update no longer supports this. However there is a work around as proposed by treehouse
1) Change your project back to using "AppTheme" like it was before in AndroidManifest.xml and the preview.
2) Add the following two lines to the file res/values/styles.xml (inside the <style name="AppTheme"> tag):
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
3) Set the background color to black in the file res/layout/activity_main.xml. The root element, RelativeLayout, is the one that makes up the whole screen. Add this line after the layout_height line but before the closing angle bracket >:
android:background="@android:color/black"
4) Change MainActivity to extend Activity, not ActionBarActivity
Hope this helps. Ask again if you have doubts.
Philip Harris
4,837 Pointssorry where do i add the 2 lines ? <resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Philip Harris
4,837 PointsPhilip Harris
4,837 Pointsthis is what i got off of the log 07-04 18:45:27.052: D/AndroidRuntime(1122): Shutting down VM 07-04 18:45:27.052: W/dalvikvm(1122): threadid=1: thread exiting with uncaught exception (group=0xb3a53ba8) 07-04 18:45:27.112: E/AndroidRuntime(1122): FATAL EXCEPTION: main 07-04 18:45:27.112: E/AndroidRuntime(1122): Process: com.example.crystalball, PID: 1122 07-04 18:45:27.112: E/AndroidRuntime(1122): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crystalball/com.example.crystalball.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread.access$800(ActivityThread.java:135) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.os.Handler.dispatchMessage(Handler.java:102) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.os.Looper.loop(Looper.java:136) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread.main(ActivityThread.java:5017) 07-04 18:45:27.112: E/AndroidRuntime(1122): at java.lang.reflect.Method.invokeNative(Native Method) 07-04 18:45:27.112: E/AndroidRuntime(1122): at java.lang.reflect.Method.invoke(Method.java:515) 07-04 18:45:27.112: E/AndroidRuntime(1122): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 07-04 18:45:27.112: E/AndroidRuntime(1122): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 07-04 18:45:27.112: E/AndroidRuntime(1122): at dalvik.system.NativeStart.main(Native Method) 07-04 18:45:27.112: E/AndroidRuntime(1122): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98) 07-04 18:45:27.112: E/AndroidRuntime(1122): at com.example.crystalball.MainActivity.onCreate(MainActivity.java:19) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.Activity.performCreate(Activity.java:5231) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 07-04 18:45:27.112: E/AndroidRuntime(1122): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 07-04 18:45:27.112: E/AndroidRuntime(1122): ... 11 more 07-04 18:45:32.642: I/Process(1122): Sending signal. PID: 1122 SIG: 9