1. You want that $100.00 in your pocket or an Amazon Fire TV don't you? Well here's the deal. With our new updated look we are in desperate need of an updated logo. The 'old' one has certainly served us well, but it's time. Find all the details here: bit.ly/1q0k6Wa
  2. DroidForums.net is currently undergoing a major software upgrade. If you are experiencing any problems logging in please: Contact Us

Can anyone help with my first app?

Discussion in 'Android Hacks and Help' started by Willocks, Jan 26, 2012.

  1. Willocks
    Offline

    Willocks New Member

    Joined:
    Nov 18, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Here is my first app (a basic calculator app to add up the numbers of coins you have, then to tell you the total dollar amount it equals) that I have tried to create to get started programming in Android but I am getting an error which is causing the app to force close when I click the calculate button. Here is my .java file and main.xml file. If anyone can help me I would greatly appreciate it, I have learned programming in a few different languages but it just seems this more difficult to learn. Maybe is just eclipse, its just the sometimes i can save a file without any errors then when i open it back up the next day errors will show up then if i resave the file they go away sometimes. So any advice on maybe why i'm having troubles (unless its just eclipse is odd sometimes or something) would also be appreciated. I have created some fairly intricate VB and C++ programs but never had troubles creating a simple program like this one. Thanks in advance for anyone that can help me solve my problem.




    Code:
    package com.innovativesolutions.utilities.change;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    import com.innovativesolutions.utilities.change.R;
    
    
    public class ChangecounterActivity extends Activity
    {
    private EditText numpen;
    private EditText numnic;
    private EditText numdim;
    private EditText numqua;
    private EditText numdol;
    private EditText numfdol;
    private EditText nummisc;
    private EditText answer;
    private Button btncalculate;
    private Button btnreset;
    private double penny = 0;
    private double nickel = 0;
    private double dime=0;
    private double quarter = 0;
    private double dollar = 0;
    private double fdollar = 0;
    private double misc = 0;
    private double tot = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    initControls();
    }
    private void initControls()
    {
    numpen = (EditText)findViewById(R.id.numpen);
    numnic = (EditText)findViewById(R.id.numnic);
    numdim = (EditText)findViewById(R.id.numdim);
    numqua = (EditText)findViewById(R.id.numqua);
    numdol = (EditText)findViewById(R.id.numdol);
    numfdol = (EditText)findViewById(R.id.numfdol);
    nummisc = (EditText)findViewById(R.id.nummisc);
    answer = (EditText)findViewById(R.id.answer);
    btncalculate = (Button)findViewById(R.id.btncalculate);
    btnreset = (Button)findViewById(R.id.btnreset);
    btncalculate.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ calculate(); }});
    btnreset.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ reset(); }});
    }
    private void calculate()
    {
    penny=Double.parseDouble(numpen.getText().toString());
    nickel=Double.parseDouble(numnic.getText().toString());
    dime=Double.parseDouble(numdim.getText().toString());
    quarter=Double.parseDouble(numqua.getText().toString());
    dollar=Double.parseDouble(numdol.getText().toString());
    fdollar=Double.parseDouble(numfdol.getText().toString());
    misc=Double.parseDouble(nummisc.getText().toString());
    
    
    tot=penny*.01+nickel*.05+dime*.1+quarter*.25+dollar+fdollar*5+misc;
    
    
    answer.setText(Double.toString(tot));
    
    
    }
    private void reset()
    {
    numpen.setText("");
    numnic.setText("");
    numdim.setText("");
    numqua.setText("");
    numdol.setText("");
    numfdol.setText("");
    nummisc.setText("");
    }
    }
    
    **************Here is the start of my main.xml file*******************


    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout
    
    
    android:layout_width="fill_parent"
    xmlns:android="(http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content">
        <TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height='80dp'>
            <TextView android:layout_width="wrap_content" android:id="@+id/widget30" android:layout_height="wrap_content" android:text="Pennies"></TextView>
            <EditText android:text="" android:textSize="18sp" android:id="@+id/numpen" android:layout_width="51px" android:layout_height="wrap_content"><requestFocus></requestFocus></EditText>
        </TableRow>
    
    
        <TableRow android:id="@+id/tableRow2" android:layout_width="wrap_content" android:layout_height='80dp'>
        <TextView android:id="@+id/widget31" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Nickels"></TextView>
        <EditText android:text="" android:textSize="18sp" android:id="@+id/numnic" android:layout_width="wrap_content" android:layout_height="wrap_content"><requestFocus></requestFocus></EditText>
        </TableRow>
    
    
    <TableRow android:id="@+id/tableRow3" android:layout_width="wrap_content" android:layout_height='80dp'>
    <TextView android:id="@+id/widget32" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Dimes"></TextView>
    <EditText android:text="" android:textSize="18sp" android:id="@+id/numdim" android:layout_width="wrap_content" android:layout_height="wrap_content"><requestFocus></requestFocus></EditText>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow4" android:layout_width="wrap_content" android:layout_height='49dp'>
    <TextView android:id="@+id/widget33" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Quarters"></TextView>
    <EditText android:id="@+id/numqua" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""><requestFocus></requestFocus></EditText>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow5" android:layout_width="wrap_content" android:layout_height='49dp'>
    <TextView android:id="@+id/widget34" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1$"></TextView>
    <EditText android:id="@+id/numdol" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""><requestFocus></requestFocus></EditText>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content" android:layout_height='49dp'>
    <TextView android:id="@+id/widget35" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="5$"></TextView>
    <EditText android:id="@+id/numfdol" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""><requestFocus></requestFocus></EditText>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content" android:layout_height='49dp'>
    <TextView android:id="@+id/widget36" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Misc"></TextView>
    <EditText android:id="@+id/nummisc" android:textSize="18sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=""><requestFocus></requestFocus></EditText>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow8" android:layout_width="wrap_content" android:layout_height='49dp'>
    <Button android:text="Reset" android:layout_height="wrap_content" android:id="@+id/btnreset" android:layout_width="100dp"></Button>
    <Button android:text="Calculate" android:layout_width="100dp" android:layout_height="wrap_content" android:id="@+id/btncalculate"></Button>
    </TableRow>
    
    
    <TableRow android:id="@+id/tableRow9" android:layout_width="wrap_content" android:layout_height='49dp'>
    <TextView android:id="@+id/widget37" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Total="></TextView>
    <EditText android:id="@+id/answer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0.00"></EditText>
    </TableRow>
    </TableLayout>
  2. aqworldthunder
    Offline

    aqworldthunder Darth Droid

    Joined:
    Feb 8, 2012
    Messages:
    384
    Likes Received:
    1
    Trophy Points:
    0
    I don't really see what's wrong here, sorry wish i could help.

    -AqworldThunder ;) ^…^ ¶.¶ *.* Thank me if i helped please!
  3. xksoftwaredev
    Offline

    xksoftwaredev Developer Developer

    Joined:
    Apr 12, 2012
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    This also looks good to me. Could you post the stack trace? Perhaps your problem is in the XML manifest file. In any case, if we don't know what exception is being thrown, its hard to spot check what could be causing the error :/