Jump to content
Sign in to follow this  
sys

sempre o mesmo erro - Android

Recommended Posts

sys

boas comecei a programar em android e sempre que tento correr o meu projecto da-me sempre o mesmo erro

ajuda sff ?

1 - Programa

uma calculadora simples

1.1 - Java code

package com.sys.learn_01;

import android.os.Bundle;
import android.app.Activity;
import android.widget.*;
import android.view.*;


public class MainActivity extends Activity {

EditText num1, num2;
Button add, sub, mult, div;
TextView resultado;
double n1, n2, result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

num1 = (EditText) findViewById(R.id.numero1);
num2 = (EditText) findViewById(R.id.numero2);
add = (Button) findViewById(R.id.add);
sub = (Button) findViewById(R.id.sub);
div = (Button) findViewById(R.id.div);
mult = (Button) findViewById(R.id.mult);
resultado = (TextView) findViewById(R.id.resultado);  



add.setonclickListener(new View.onclickListener() {
public void onclick(View v) {

n1 = Double.parseDouble(num1.getText().toString());
n2 = Double.parseDouble(num2.getText().toString());
result = n1 + n2;
resultado.setText(String.valueOf(result));
num1.setText("");
num2.setText("");
}
});

sub.setonclickListener(new View.onclickListener() {
public void onclick(View v) {

n1 = Double.parseDouble(num1.getText().toString());
n2 = Double.parseDouble(num2.getText().toString());
result = n1 - n2;
resultado.setText(String.valueOf(result));
num1.setText("");
num2.setText("");
}
});

div.setonclickListener(new View.onclickListener() {
public void onclick(View v) {

n1 = Double.parseDouble(num1.getText().toString());
n2 = Double.parseDouble(num2.getText().toString());
result = n1 / n2;
resultado.setText(String.valueOf(result));
num1.setText("");
num2.setText("");
}
});

mult.setonclickListener(new View.onclickListener() {
public void onclick(View v) {

n1 = Double.parseDouble(num1.getText().toString());
n2 = Double.parseDouble(num2.getText().toString());
result = n1 * n2;
resultado.setText(String.valueOf(result));
num1.setText("");
num2.setText("");
}
});

}
}

1.2 - xml code

<RelativeLayout xmlns:android="http://schemas.andro...apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<EditText
	android:id="@+id/numero1"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_alignParentTop="true"
	android:layout_centerHorizontal="true"
	android:ems="10"
	android:inputType="text"
	android:text="@string/n1" />

<EditText
	android:id="@+id/numero2"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_alignLeft="@+id/numero1"
	android:layout_below="@+id/numero1"
	android:layout_marginTop="14dp"
	android:ems="10"
	android:inputType="text"
	android:text="@string/n2" />

<Button
	android:id="@+id/add"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_below="@+id/numero2"
	android:layout_centerHorizontal="true"
	android:layout_marginTop="16dp"
	android:text="@string/add" />

<Button
	android:id="@+id/sub"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_alignLeft="@+id/add"
	android:layout_below="@+id/add"
	android:text="@string/sub" />

<Button
	android:id="@+id/div"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_below="@+id/sub"
	android:layout_centerHorizontal="true"
	android:text="@string/div" />

<Button
	android:id="@+id/mult"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_below="@+id/div"
	android:layout_centerHorizontal="true"
	android:text="@string/mult" />

<TextView
	android:id="@+id/resultado"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:layout_below="@+id/mult"
	android:layout_centerHorizontal="true"
	android:layout_marginTop="15dp"
	android:gravity="center"
	android:text="@string/result"
	android:textSize="30sp"
	android:textStyle="bold" />

</RelativeLayout>

2 - versao do java

actualizada e de 64bits

3 - SO

windows 8.1

4 - programa

Android Developer Tools

Build: v22.2.1-833290

5 - ERRO

Consola :

[2013-11-03 01:05:37 - Android SDK] Warning when loading the SDK:

Warning: Ignoring platform 'android-19': build.prop is missing.

[2013-11-03 01:07:54 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

[2013-11-03 01:07:54 - learn_calculadoraV1] Conversion to Dalvik format failed: Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.

6 - uma simples questão

porque é que nao posso no xml na parte do text de um objecto meter algo sem ser usado como string ? eu a uns tempos metia e agora não deixa

Edited by Rui Carlos
GeSHi

Share this post


Link to post
Share on other sites
KTachyon

Parece ser uma issue com o SDK 19. Experimenta para a versão 18.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
KTachyon

Sim, mas o problema está em compilares com a versão 19 e não a versão onde queres executar.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.