I am supposed to make a app for class that takes the input from the user in the case number of people and the cost of the bill and then tells you what the cost is per person with the tip added in. The thing is it looks like it should work but i am new to this so not sure but everytime i run the emulator in eclipse it keeps saying that my app has stopped working please help. here is my code. up first mainactivity.
package com.example.splitbill;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
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;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.btnCalc);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this, Calc.class));
}
});
}
@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);
}
}
then my second activity which is called Calc
package com.example.splitbill;
import java.text.DecimalFormat;
import android.app.Activity;
import android.os.Bundle;
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 Calc extends Activity {
double totalOfBill;
int numberOfGuests;
double perPersonSplit;
String groupChoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.calc);
final EditText guests=(EditText)findViewById(R.id.txtGuests);
final EditText bill=(EditText)findViewById(R.id.txtBill);
final Spinner group = (Spinner)findViewById(R.id.txtGroup);
Button cost = (Button)findViewById(R.id.btnSplit);
cost.setOnClickListener(new OnClickListener() {
final TextView result = ((TextView)findViewById(R.id.txtResult));
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
totalOfBill = Double.parseDouble(bill.getText().toString());
numberOfGuests = Integer.parseInt(guests.getText().toString());
perPersonSplit = (totalOfBill * .18 +totalOfBill) / numberOfGuests;
DecimalFormat currency = new DecimalFormat("$###,###.##");
groupChoice = group.getSelectedItem().toString();
result.setText("Quality is " + groupChoice + "cost is " + currency.format(perPersonSplit));
}
});
}
}
If anyone can help that would be awesome. some one asked me for the error log here it is i think
02-03 16:53:14.297: D/AndroidRuntime(1043): Shutting down VM
02-03 16:53:14.297: D/AndroidRuntime(1043): --------- beginning of crash
02-03 16:53:14.312: E/AndroidRuntime(1043): FATAL EXCEPTION: main
02-03 16:53:14.312: E/AndroidRuntime(1043): Process: com.example.splitbill, PID: 1043
02-03 16:53:14.312: E/AndroidRuntime(1043): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.splitbill/com.example.splitbill.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread.access$800(ActivityThread.java:144)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.os.Handler.dispatchMessage(Handler.java:102)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.os.Looper.loop(Looper.java:135)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread.main(ActivityThread.java:5221)
02-03 16:53:14.312: E/AndroidRuntime(1043): at java.lang.reflect.Method.invoke(Native Method)
02-03 16:53:14.312: E/AndroidRuntime(1043): at java.lang.reflect.Method.invoke(Method.java:372)
02-03 16:53:14.312: E/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
02-03 16:53:14.312: E/AndroidRuntime(1043): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
02-03 16:53:14.312: E/AndroidRuntime(1043): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:151)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:138)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
02-03 16:53:14.312: E/AndroidRuntime(1043): at com.example.splitbill.MainActivity.onCreate(MainActivity.java:16)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.Activity.performCreate(Activity.java:5933)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
02-03 16:53:14.312: E/AndroidRuntime(1043): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
02-03 16:53:14.312: E/AndroidRuntime(1043): ... 10 more