File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes display in output is not seen for addition program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "display in output is not seen for addition program" Watch "display in output is not seen for addition program" New topic
Author

display in output is not seen for addition program

deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
i am able to enter the input for the addition program. but i am not able to get the output on the window screen. can any one help me?

code is

package com.example.addition;


import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Button;

import android.view.View;


public class addition extends Activity
{
EditText amount1;
EditText amount2;
TextView tt;
Button calculate;
double x=0;
double y=0;
double z=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()
{
amount1=(EditText)findViewById(R.id.amount1);
amount2=(EditText)findViewById(R.id.amount2);
tt=(TextView)findViewById(R.id.tt);
calculate=(Button)findViewById(R.id.calculate);
calculate.setOnClickListener(new Button.OnClickListener()
{public void onClick
(View v) { calculate();}});
}
private void calculate()
{
x=Double.parseDouble(amount1.getText().toString());
y=Double.parseDouble(amount2.getText().toString());
z=x+y;
tt.setText(Double.toString(z));

}
}


// main.xml is

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADDITION OF NUMBERS"
android:id="@+id/textView1"
android:layout_x="73dip"
android:layout_y="28dip"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_x="36dip"
android:layout_height="wrap_content"
android:text="First Amount"
android:id="@+id/textView2"
android:layout_y="80dip"></TextView>
<EditText android:text=""
android:layout_width="wrap_content"
android:layout_x="172dip"
android:id="@+id/amount1"
android:layout_height="wrap_content"
android:layout_y="62dip"></EditText>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second Amount"
android:id="@+id/textView3"
android:layout_x="36dip"
android:layout_y="169dip"></TextView>
<EditText android:text=""
android:layout_width="wrap_content"
android:layout_x="169dip"
android:id="@+id/amount2"
android:layout_height="wrap_content"
android:layout_y="152dip"></EditText>
<Button android:layout_width="wrap_content"
android:id="@+id/calculate"
android:layout_x="41dip"
android:layout_height="wrap_content"
android:text="Calculate"
android:layout_y="232dip"></Button>
<EditText android:text=""
android:layout_width="wrap_content"
android:layout_x="172dip"
android:id="@+id/tt"
android:layout_height="wrap_content"
android:layout_y="232dip"></EditText>
</AbsoluteLayout>
can any one help me?
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

please have a look these two block of code carefully.





Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
ya in this code it is telling in line 4 "The word 'tt' is not correctly spelled".i am using eclipse.But i am unable to find an solution to get the result. can any one help me how to rectify the error and get the result?

<EditText android:text=""
android:layout_width="wrap_content"
android:layout_x="172dip"
android:id="@+id/tt"
android:layout_height="wrap_content"
android:layout_y="232dip"></EditText>
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Deepika,

Look at the code carefully. In your xml tt refers to an EditText but in your activity class TextView refers to this.


Swastik
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
EditText is a subclass of TextView, so that's not the problem.
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

Hi!

I copied your code to Eclipse. And ... seems to work good. So I do not know what the problem is? See on image.

Picture

Bye!
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
ya i am able to view your output. But still i am sung the same code but the output is not displayed. can you tell me what all things you have done and what android version you have used for for running this code?
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

Hi !

Try with this :

There is no XML file as layout creator.




This should works, it was tested on 2.2.1 android api, and Archos 70
Bye!
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
thank you for your coding . The code is fine. But some error existing in eclipse i think so the result is not displayed. i am using java EE developers for with android installed in it from the net. But is there any other way to run on windows leaving the eclipse.?
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

You want to launch your app on software device emulator ? Something like AVD (Android Virtual Device)?
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
i want to launch an application on the emulator that can be used as an application on mobile
Przemek Boryka
Ranch Hand

Joined: Dec 06, 2011
Posts: 51

So, install and use AVD

Using the Android Emulator

You must install proper API version of Android SDK (includes AVD)


deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
ya ok . will try. thank you
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
hello every body,


i have tried to attach an rar file for addition program i am using. but i am unable to upload that. can any one hell me how can i upload the whole file and find the result why in my coding alone the output is not displayed.?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I think you can only attach images, nothing else. You'll need to find some external host if you want to distribute the code, and post the link here.
deepika deepi
Ranch Hand

Joined: Jan 23, 2012
Posts: 199
hello good evening to every body..

finally i got the output on eclipse for the same code. i found my mistake and corrected... Thanks to all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display in output is not seen for addition program