February 5th, 2012, 06:46 AM
|
#1 (permalink)
|
|
New Member
Join Date: Feb 2012
Posts: 3
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
|
Gradeaverage app will not start in emulator!
Im trying to make this app that calculates your grade average (based on the Swedish grade system) and I have made the graphical layout and written the java code in eclipse that I think is right, but when I try to launch it in the emulator it won´t work. I just get the following messege. "The application Gradeaverage (process com.dlol.gradeaverage) has stopped unexpectedly. please try again. This is my first app and my first programming project so I don´t really know what I have done wrong.
It is sopposed to be three edittexts where you put the amount of points you have with a cerrtain grade (we have three grades) and then it should multiply the points with the 10, 15 or 20 depending on what grade it is and then divide by the total amount of points. I dont know if that makes sense, but the maxmimum grade is supposed to be 20 (all mvgs). I made a similar app in C# and it works, but Im guessing things are done alittle diferent when it comes to android and java.
Here is the Java code:
Code:
package com.dlol.gradeaverage;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class GradeaverageActivity extends Activity {
EditText editText1, editText2, editText3;
String gtext, vgtext, mvgtext, str;
Double gpoäng, vgpoäng, mvgpoäng;
Double gvärde, vgvärde, mvgvärde;
Double allapoäng, allavärde;
Double snittbetyg;
Button button1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText1 = (EditText)findViewById(R.id.editText1);
editText2 = (EditText)findViewById(R.id.editText2);
editText3 = (EditText)findViewById(R.id.editText3);
gtext = editText1.getText().toString();
vgtext = editText2.getText().toString();
mvgtext = editText3.getText().toString();
gpoäng = Double.parseDouble(gtext);
vgpoäng = Double.parseDouble(vgtext);
mvgpoäng = Double.parseDouble(mvgtext);
gvärde = gpoäng*10;
vgvärde = vgpoäng*15;
mvgvärde = mvgpoäng*20;
allapoäng = (gpoäng + vgpoäng + mvgpoäng);
allavärde = (gvärde + vgvärde + mvgvärde);
snittbetyg = (allavärde / allapoäng);
str = "Ditt snitt är " + snittbetyg;
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getBaseContext(), str,
Toast.LENGTH_SHORT).show();
}
});
}}
Here is the main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info_text_G"
android:textSize="16sp">
</TextView>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text">
</EditText>/
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info_text_VG"
android:textSize="16sp" />
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/info_text_MVG"
android:textSize="16sp">
</TextView>
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text">
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Button" />
</LinearLayout>
And here is the strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, GradeaverageActivity!</string>
<string name="app_name">Gradeaverage</string>
<string name="info_text_G">Skriv in antal G-poäng</string>
<string name="info_text_VG">Skriv in antal VG-poäng</string>
<string name="info_text_MVG">Skriv in antal MVG-poäng</string>
<string name="Button">Räkna ut snitt!</string>
</resources>
Thanks in advance!
|
|
|
Last edited by El Presidente; February 5th, 2012 at 12:56 PM.
Reason: Added code tags
|
|