1. Download our Official Android App: Forums for Android!

Apps need help with error in app

Discussion in 'Android Development' started by willocks1718, Jan 6, 2013.

  1. willocks1718

    willocks1718 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Apr 19, 2011

    Apr 19, 2011
    4
    0
    5
    [HIGH]
    package com.innovativesolutions.cardscorekeeper;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.CheckBox;
    import android.widget.EditText;

    public class MainActivity extends Activity {

    int scorea, scoreb, takea[], takeb[], bida[], bidb[], baga, bagb, iii;
    EditText bid1aa, bid1bb, actuala, actualb, totala, totalb;
    Button total;
    CheckBox nila, nilb, gnila, gnilb;


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    iii = 0;
    baga = 0;
    bagb = 0;
    scorea = 0;
    scoreb = 0;
    total = (Button) findViewById(R.id.button1);
    bid1aa = (EditText) findViewById(R.id.a1bid);
    bid1bb = (EditText) findViewById(R.id.b1bid);
    actuala = (EditText) findViewById(R.id.atake);
    actualb = (EditText) findViewById(R.id.btake);
    totala = (EditText) findViewById(R.id.atotal);
    totalb = (EditText) findViewById(R.id.btotal);
    nila = (CheckBox) findViewById(R.id.anil);
    nilb = (CheckBox) findViewById(R.id.bnil);
    gnila = (CheckBox) findViewById(R.id.agnil);
    gnilb = (CheckBox) findViewById(R.id.bgnil);
    total.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    // TODO Auto-generated method stub
    bida[iii]=Integer.parseInt(bid1aa.getText().toString());
    bidb[iii]=Integer.parseInt(bid1bb.getText().toString());
    takea[iii]=Integer.parseInt(actuala.getText().toString());
    takeb[iii]=Integer.parseInt(actualb.getText().toString());


    if (nila.isChecked()){
    if (gnila.isChecked() && takea[iii]>=bida[iii]){
    baga = takea[iii]-bida[iii]+baga;
    scorea = scorea + 100 + (bida[iii]*10);
    }
    else {scorea = scorea - 100 - (bida[iii]*10);}
    } else {
    if (takea[iii]>=bida[iii]){
    baga = takea[iii]-bida[iii]+baga;
    scorea = scorea + (bida[iii]*10);
    } else {scorea = scorea - (bida[iii]*10);}

    }

    if (nilb.isChecked()){
    if (gnilb.isChecked() && takeb[iii]>=bidb[iii]){
    bagb = takeb[iii]-bidb[iii]+bagb;
    scoreb = scoreb + 100 + (bidb[iii]*10);
    } else {scoreb = scoreb - 100 - (bidb[iii]*10);}
    } else {
    if (takeb[iii]>=bidb[iii]){
    bagb = takeb[iii]-bidb[iii]+bagb;
    scoreb = scoreb + (bidb[iii]*10);
    } else {scoreb = scoreb - (bidb[iii]*10);}

    }


    if (baga>=10){
    scorea = scorea - 100;
    baga = 0;
    }
    if (bagb>=10){
    scoreb = scoreb - 100;
    bagb = 0;
    }

    iii++;
    totala.setText(scorea);
    totalb.setText(scoreb);

    }
    });


    }}




    [/HIGH]

    *******************and here is my xml file

    [HIGH]
    <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" >

    <RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <RadioButton
    android:id="@+id/radio0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:checked="true"
    android:text="Spades" />

    <RadioButton
    android:id="@+id/radio1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rook" />
    </RadioGroup>

    <EditText
    android:id="@+id/atotal"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="50dp"
    android:ems="10"
    android:text="13" >

    <requestFocus />
    </EditText>

    <EditText
    android:id="@+id/btotal"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="50dp"
    android:ems="10"
    android:inputType="number"
    android:text="13" />

    <EditText
    android:id="@+id/editText3"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/radioGroup1"
    android:layout_marginLeft="70dp"
    android:ems="10"
    android:text="Team A"
    android:textSize="20dp" />

    <EditText
    android:id="@+id/editText4"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radioGroup1"
    android:layout_marginLeft="50dp"
    android:layout_toRightOf="@+id/editText3"
    android:ems="10"
    android:text="Team B"
    android:textSize="20dp" />

    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="75dp"
    android:layout_marginTop="20dp"
    android:layout_toRightOf="@+id/radioGroup1"
    android:text="Add Round" />

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/editText3"
    android:text="Bid"
    android:textSize="20dp" />

    <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:text="Taken"
    android:textSize="20dp" />

    <EditText
    android:id="@+id/a1bid"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/textView1"
    android:layout_toRightOf="@+id/textView2"
    android:ems="10"
    android:inputType="number"
    android:text="0"
    android:textSize="20dp" />

    <EditText
    android:id="@+id/b1bid"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/textView2"
    android:layout_marginLeft="50dp"
    android:layout_toRightOf="@+id/editText3"
    android:ems="10"
    android:inputType="number"
    android:text="0"
    android:textSize="20dp" />

    <EditText
    android:id="@+id/btake"
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText4"
    android:layout_alignRight="@+id/b1bid"
    android:layout_alignTop="@+id/textView2"
    android:ems="10"
    android:inputType="number"
    android:text="0"
    android:textSize="20dp" />

    <CheckBox
    android:id="@+id/anil"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/a1bid"
    android:layout_alignBottom="@+id/a1bid"
    android:layout_toRightOf="@+id/a1bid"
    android:checked="false"
    android:text="Nil?" />

    <CheckBox
    android:id="@+id/bnil"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/b1bid"
    android:layout_alignBottom="@+id/b1bid"
    android:layout_alignParentRight="true"
    android:text="Nil?" />

    <CheckBox
    android:id="@+id/bgnil"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/btake"
    android:layout_alignBottom="@+id/btake"
    android:layout_alignParentRight="true"
    android:text="Nil?" />

    <EditText
    android:id="@+id/atake"
    android:layout_width="50dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/editText3"
    android:layout_below="@+id/a1bid"
    android:ems="10"
    android:inputType="number"
    android:text="0"
    android:textSize="20dp" />

    <CheckBox
    android:id="@+id/agnil"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/atake"
    android:layout_alignBottom="@+id/atake"
    android:layout_centerHorizontal="true"
    android:checked="false"
    android:text="Nil?" />

    </RelativeLayout>

    [/HIGH]


    For some reason I keep getting a force close error and I am not really good at using logcat yet so any help would be appreciated. This is the start a app i am making to keep score for spades.
     

    Advertisement

  2. redpipe

    redpipe Newbie
    Rank:
    None
    Points:
    16
    Posts:
    29
    Joined:
    Aug 2, 2012

    Aug 2, 2012
    29
    7
    16
    Zip and send me your app and I will find out what's making it crash
     
  3. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    Can you post the log cat output?
     
  4. GeorgeN

    GeorgeN Well-Known Member
    Rank:
    None
    Points:
    73
    Posts:
    132
    Joined:
    Apr 16, 2012

    Apr 16, 2012
    132
    38
    73
    Male
    London
    It looks like you have defined a load of arrays but not actually constructed them. I guess it crashes with a null pointer exception when you call:

    [HIGH]bida[iii]=Integer.parseInt(bid1aa.getText().toString())[/HIGH]Call bida = new int[10]; to construct an array big enough to hold 10 integers (do all the rest too). You will need to make sure iii doesn't get bigger than the size of the array.
     

Share This Page

Loading...