Can anyone help with my first app?

This is a discussion on Can anyone help with my first app? within the Droid Development forums, part of the Droid Hacking category; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Can anyone help with my first app?

  1. Droid Newbie
    Willocks's Avatar
    Member #
    138925
    Join Date
    Nov 2010
    Posts
    2
    Phone
    droid 2
    #1

    Can anyone help with my first app?

    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. Sponsor
    DF Advertising
    Join Date
    Nov 2008
    Location
    DroidForums.net
     
     
     
     
  3. Darth Droid
    aqworldthunder's Avatar
    Member #
    250613
    Join Date
    Feb 2012
    Posts
    385
    Liked
    4 times
    Phone
    Android 2.1
    #2
    I don't really see what's wrong here, sorry wish i could help.

    -AqworldThunder ^…^ ¶.¶ *.* Thank me if i helped please!
  4. Developer
    xksoftwaredev's Avatar
    Member #
    258819
    Join Date
    Apr 2012
    Posts
    17
    Liked
    1 times
    Phone
    LG Spectrum
    DroidForums.net Developer
    #3
    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 :/

Sponsors

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts