-3

I am new to Android App development and I am having an issue with an app. I have read everything I could find on stackoverflow about the problem and checked my work against the suggestions from the other questions asked.

Thanks for the help.

Unfortunately application has stopped android emulator genymotion I am trying to run the app on a Samsung Gal 3 tab. Below are my files

MainActivity.java

    package net.androidbootcamp.concerttickets;

    import java.text.DecimalFormat;

    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Spinner;
    import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

    double costPerTicket = 79.99;
    int numberOfTickets;
    double totalCost;
    String groupChoice;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final EditText tickets=(EditText)findViewById(R.id.txtTicket);
        final Spinner group = (Spinner)findViewById(R.id.txtGroup);
        Button cost = (Button)findViewById(R.id.btnCost);
        cost.setOnClickListener(new OnClickListener() {
            final TextView result = ((TextView)findViewById(R.id.txtResult));

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                numberOfTickets = Integer.parseInt(tickets.getText().toString());
                totalCost = costPerTicket * numberOfTickets;
                DecimalFormat currency = new DecimalFormat("$###,###.##");
                groupChoice = group.getSelectedItem().toString();
                result.setText("Total Cost for" + groupChoice + "is" +     currency.format(totalCost));

            }
        });
    }

    @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);
    }
}

ActivityMain.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="net.androidbootcamp.concerttickets.MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/txtTitle"
        android:textSize="48sp" />

    <EditText
        android:id="@+id/txtTicket"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/txtGroup"
        android:layout_below="@+id/textView1"
        android:ems="10"
        android:hint="@string/txtTickets"
        android:inputType="number"
        android:textSize="32sp" >

        <requestFocus />
    </EditText>

    <Spinner
        android:id="@+id/txtGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtTicket"
        android:layout_centerHorizontal="true"
        android:entries="@array/txtGroup"
        android:prompt="@string/prompt" />

    <Button
        android:id="@+id/btnCost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/txtGroup"
        android:layout_centerHorizontal="true"
        android:text="@string/btnCost"
        android:textSize="32sp" />

    <TextView
        android:id="@+id/txtResult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnCost"
        android:layout_centerHorizontal="true"
        android:textSize="18sp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/txtGroup"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="19dp"
        android:contentDescription="@string/description"
        android:src="@drawable/concert" />

</RelativeLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.androidbootcamp.concerttickets"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >
        <activity
            android:name="net.androidbootcamp.concerttickets.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

LogCat
08-14 17:19:35.330: D/AndroidRuntime(20330): Shutting down VM
08-14 17:19:35.330: W/dalvikvm(20330): threadid=1: thread exiting with uncaught exception (group=0x41cf0e10)
08-14 17:19:35.340: E/AndroidRuntime(20330): FATAL EXCEPTION: main
08-14 17:19:35.340: E/AndroidRuntime(20330): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.androidbootcamp.concerttickets/net.androidbootcamp.concerttickets.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2245)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2295)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread.access$700(ActivityThread.java:150)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.os.Looper.loop(Looper.java:176)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread.main(ActivityThread.java:5279)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at java.lang.reflect.Method.invokeNative(Native Method)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at java.lang.reflect.Method.invoke(Method.java:511)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at dalvik.system.NativeStart.main(Native Method)
08-14 17:19:35.340: E/AndroidRuntime(20330): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:110)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:99)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at net.androidbootcamp.concerttickets.MainActivity.onCreate(MainActivity.java:26)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.Activity.performCreate(Activity.java:5267)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
08-14 17:19:35.340: E/AndroidRuntime(20330):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2209)
08-14 17:19:35.340: E/AndroidRuntime(20330):    ... 11 more
Community
  • 1
  • 1
  • 1
    How do you expect anyone to help if you dont post the crash log? We cant compile and run code in our heads, we arent THAT good. – r2DoesInc Aug 14 '14 at 19:38
  • 2
    http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – nhaarman Aug 14 '14 at 19:39
  • 1
    What do you mean by issue?Please see the logcat and paste it here so that we can check what exception you are getting. – Sash_KP Aug 14 '14 at 19:39
  • 4
    `I have read everything I could find on stackoverflow` - really? How did you miss that you must include the crash log? – Simon Aug 14 '14 at 19:40

1 Answers1

0

The LogCat output shows that you aren't using the theme correctly. in particular, it wants you to use a compatibility theme. You can do that by altering/including a theme attribute for the activity in your manifest file.

If you're not actually going to use an action bar, your could also just change the parent of your activity from ActionbarActivity to just Activity like this:

public class MainActivity extends Activity {
scottt
  • 8,301
  • 1
  • 31
  • 41
  • Thank you for your help. I will make the changes . – user3748283 Aug 15 '14 at 14:11
  • 1
    I made the changes to theme and the class change and the APP worked. Thank you again, I learned something today. – user3748283 Aug 15 '14 at 15:00
  • There's no need to add "thank you" comments. If someone has helped you, the best way to thank them is to accept their answer (be clicking the check-mark next to their answer) and/or up-voting (by clicking the up-arrow) if you've attained that privilege. I don't suspect you can do either on closed questions, but something to know for the future. BTW, You can also up-vote comments. – scottt Aug 18 '14 at 15:55