Notengrenzenrechner

  • Antworten:7
Lucas Gregor
  • Forum-Beiträge: 16

27.08.2013, 19:05:31 via Website

Hallo erst mal ich soll für die Schule eine App entwickeln die die Punktegrenzen bei Arbeiten berechnet allerdings crasht diese immer wenn ich den Button drücke und eine Zahl bei dem Textfeld eingegeben habe wo die Gesammt Punkte eingetragen werden sollen. Ist dort keine Zahl angegeben passiert wie geplant nichts ist eine angegeben crasht die App. Per debuggen kann ich nicht prüfen da dann die Fehlermeldung kommt :
[2013-08-27 18:32:05 - Emulator] Failed to allocate memory: 8
[2013-08-27 18:32:05 - Emulator]
[2013-08-27 18:32:05 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2013-08-27 18:32:05 - Emulator] Please contact the application's support team for more information.

Hier die MainActivity class:
1public void Rechnen (View view) {
2 int GesammtPunkte;
3 int Note1;
4 int Note2;
5 int Note3;
6 int Note4;
7 int Note5;
8 int Note6;
9
10 EditText Gesammt = (EditText)findViewById(R.id.Punkte);
11 EditText Feld1 = (EditText)findViewById(R.id.Punkte1);
12 EditText Feld2 = (EditText)findViewById(R.id.Punkte2);
13 EditText Feld3 = (EditText)findViewById(R.id.Punkte3);
14 EditText Feld4 = (EditText)findViewById(R.id.Punkte4);
15 EditText Feld5 = (EditText)findViewById(R.id.Punkte5);
16 EditText Feld6 = (EditText)findViewById(R.id.Punkte6);
17 if (Gesammt.getText().toString().length() == 0) {
18 return;
19 }
20 GesammtPunkte = Integer.parseInt(Gesammt.getText().toString());
21
22 Note1 = GesammtPunkte/100*95;
23 Note2 = GesammtPunkte/100*80;
24 Note3 = GesammtPunkte/100*65;
25 Note4 = GesammtPunkte/100*50;
26 Note5 = GesammtPunkte/100*30;
27 Note6 = GesammtPunkte/100*0;
28
29
30 Feld1.setText(Note1);
31 Feld2.setText(Note2);
32 Feld3.setText(Note3);
33 Feld4.setText(Note4);
34 Feld5.setText(Note5);
35 Feld6.setText(Note6);
36 }

Und hier die activity_main:
1<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
2 android:layout_width="fill_parent"
3 android:layout_height="fill_parent"
4 android:gravity="center_horizontal"
5 android:orientation="vertical" >
6
7 <TextView
8 android:id="@+id/textView1"
9 android:layout_width="250dp"
10 android:layout_height="wrap_content"
11 android:text="@string/GesammtPunkte"
12 android:textAppearance="?android:attr/textAppearanceLarge" />
13
14 <TextView
15 android:id="@+id/textView2"
16 android:layout_width="wrap_content"
17 android:layout_height="50dp" />
18
19 <EditText
20 android:id="@+id/Punkte"
21 android:layout_width="wrap_content"
22 android:layout_height="wrap_content"
23 android:ems="10"
24 android:inputType="number" >
25
26 <requestFocus />
27 </EditText>
28
29 <TextView
30 android:id="@+id/textView3"
31 android:layout_width="wrap_content"
32 android:layout_height="50dp" />
33
34 <TextView
35 android:id="@+id/textView8"
36 android:layout_width="wrap_content"
37 android:layout_height="wrap_content"
38 android:text="@string/Punktegrenze1"
39 android:textAppearance="?android:attr/textAppearanceLarge" />
40
41 <TextView
42 android:id="@+id/textView4"
43 android:layout_width="wrap_content"
44 android:layout_height="50dp" />
45
46 <EditText
47 android:id="@+id/Punkte1"
48 android:layout_width="wrap_content"
49 android:layout_height="wrap_content"
50 android:ems="10"
51 android:inputType="number" />
52
53 <TextView
54 android:id="@+id/textView5"
55 android:layout_width="wrap_content"
56 android:layout_height="50dp" />
57
58 <TextView
59 android:id="@+id/textView15"
60 android:layout_width="wrap_content"
61 android:layout_height="wrap_content"
62 android:text="@string/Punktegrenze2"
63 android:textAppearance="?android:attr/textAppearanceLarge" />
64
65 <TextView
66 android:id="@+id/textView6"
67 android:layout_width="wrap_content"
68 android:layout_height="50dp" />
69
70 <EditText
71 android:id="@+id/Punkte2"
72 android:layout_width="wrap_content"
73 android:layout_height="wrap_content"
74 android:ems="10"
75 android:inputType="number" />
76
77 <TextView
78 android:id="@+id/textView7"
79 android:layout_width="wrap_content"
80 android:layout_height="50dp" />
81
82 <TextView
83 android:id="@+id/textView22"
84 android:layout_width="wrap_content"
85 android:layout_height="wrap_content"
86 android:text="@string/Punktegrenze3"
87 android:textAppearance="?android:attr/textAppearanceLarge" />
88
89 <TextView
90 android:id="@+id/textView9"
91 android:layout_width="wrap_content"
92 android:layout_height="50dp" />
93
94 <EditText
95 android:id="@+id/Punkte3"
96 android:layout_width="wrap_content"
97 android:layout_height="wrap_content"
98 android:ems="10"
99 android:inputType="number" />
100
101 <TextView
102 android:id="@+id/textView10"
103 android:layout_width="wrap_content"
104 android:layout_height="50dp" />
105
106 <TextView
107 android:id="@+id/textView29"
108 android:layout_width="wrap_content"
109 android:layout_height="wrap_content"
110 android:text="@string/Punktegrenze4"
111 android:textAppearance="?android:attr/textAppearanceLarge" />
112
113 <TextView
114 android:id="@+id/textView11"
115 android:layout_width="wrap_content"
116 android:layout_height="50dp" />
117
118 <EditText
119 android:id="@+id/Punkte4"
120 android:layout_width="wrap_content"
121 android:layout_height="wrap_content"
122 android:ems="10"
123 android:inputType="number" />
124
125 <TextView
126 android:id="@+id/textView12"
127 android:layout_width="wrap_content"
128 android:layout_height="50dp" />
129
130 <TextView
131 android:id="@+id/textView36"
132 android:layout_width="wrap_content"
133 android:layout_height="wrap_content"
134 android:text="@string/Punktegrenze5"
135 android:textAppearance="?android:attr/textAppearanceLarge" />
136
137 <TextView
138 android:id="@+id/textView13"
139 android:layout_width="wrap_content"
140 android:layout_height="50dp" />
141
142 <EditText
143 android:id="@+id/Punkte5"
144 android:layout_width="wrap_content"
145 android:layout_height="wrap_content"
146 android:ems="10"
147 android:inputType="number" />
148
149 <TextView
150 android:id="@+id/textView14"
151 android:layout_width="wrap_content"
152 android:layout_height="50dp" />
153
154 <TextView
155 android:id="@+id/textView43"
156 android:layout_width="wrap_content"
157 android:layout_height="wrap_content"
158 android:text="@string/Punktegrenze6"
159 android:textAppearance="?android:attr/textAppearanceLarge" />
160
161 <TextView
162 android:id="@+id/textView16"
163 android:layout_width="wrap_content"
164 android:layout_height="25dp" />
165
166 <EditText
167 android:id="@+id/Punkte6"
168 android:layout_width="wrap_content"
169 android:layout_height="wrap_content"
170 android:ems="10"
171 android:inputType="number" />
172
173 <Button
174 android:id="@+id/button1"
175 android:layout_width="813dp"
176 android:layout_height="wrap_content"
177 android:onClick="Rechnen"
178 android:text="@string/Berechnen" />
Die kleinen Textviewer ohne Text dienen als Abstandshalter und das http beim Layout fehlt weil ich woll als anfänger noch keine Links posten darf

Ich habe schon viel probiert finde aber den Fehler nicht kann auch sein das ich etwas total falsch gemacht habe da ich programmier anfänger bin
Freue mich auf Antwort

Antworten
Christian
  • Forum-Beiträge: 307

27.08.2013, 19:15:25 via Website

Hi Lucas,

Und wieder das übliche Spiel wenn deine App crasht steht der Fehler in der LogCat.
Falls du nicht weißt wo sie ist du findest sie in Eclipse unter Windwo -> show View -> Other -> Anroid -> LogCat.

Such den Fehler raus und wenn du ihn nicht verstehst poste ihn hier nochmal.

Mfg Christian

PS. in Java werden nur Klassen großgeschrieben

P.s.s die Rechnung für die Note 6 ist leicht sinnlos

— geändert am 27.08.2013, 19:19:13

Antworten
Lucas Gregor
  • Forum-Beiträge: 16

27.08.2013, 19:25:12 via Website

Ich kann wie bereits geschrieben die App nich direkt debuggen sondern erst wenn ich sie zur einer .apk umgewandelt haben und dann auf dem handy instaliert habe wenn ich direkt debugge also per usb oder emulator kommt ohne das überhaupt etwas startet die fehler meldung
[2013-08-27 19:19:06 - Emulator] Failed to allocate memory: 8
[2013-08-27 19:19:06 - Emulator]
[2013-08-27 19:19:06 - Emulator] This application has requested the Runtime to terminate it in an unusual way.
[2013-08-27 19:19:06 - Emulator] Please contact the application's support team for more information.
in der console deshalb wird doch im logcat nichts angezeigt weil ich die app nicht über eclipse zum laufen krige oder ihre ich mich da?

Ps.: ich weiß das note 6 sinnlos ist aber wenn ich sie weglasse habe ich ständig das gefühl das was fehl könnte ja die note 6 zeilen in der java activity rausnehmen und das edit text feld mit string füllen

— geändert am 27.08.2013, 19:27:58

Antworten
Michele
  • Forum-Beiträge: 1.525

27.08.2013, 19:39:02 via Website

Hallo.

Ja und was steht da? Failed to allocate memory: 8

Setz bei deinen Emulator Max den Arbeitsspeicher auf 768mb.


LG

— geändert am 27.08.2013, 19:39:50

impjor

Antworten
Lucas Gregor
  • Forum-Beiträge: 16

27.08.2013, 20:37:26 via Website

108-27 18:29:46.153: D/gralloc_goldfish(693): Emulator without GPU emulation detected.
208-27 18:30:19.073: W/InputEventReceiver(693): Attempted to finish an input event but the input event receiver has already been disposed.
308-27 18:30:44.902: W/ResourceType(693): No package identifier when getting value for resource number 0x0000005f
408-27 18:30:44.912: D/AndroidRuntime(693): Shutting down VM
508-27 18:30:44.912: W/dalvikvm(693): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
608-27 18:30:44.992: E/AndroidRuntime(693): FATAL EXCEPTION: main
708-27 18:30:44.992: E/AndroidRuntime(693): java.lang.IllegalStateException: Could not execute method of the activity
808-27 18:30:44.992: E/AndroidRuntime(693): at android.view.View$1.onClick(View.java:3591)
908-27 18:30:44.992: E/AndroidRuntime(693): at android.view.View.performClick(View.java:4084)
1008-27 18:30:44.992: E/AndroidRuntime(693): at android.view.View.onKeyUp(View.java:7669)
1108-27 18:30:44.992: E/AndroidRuntime(693): at android.widget.TextView.onKeyUp(TextView.java:5382)
1208-27 18:30:44.992: E/AndroidRuntime(693): at android.view.KeyEvent.dispatch(KeyEvent.java:2633)
1308-27 18:30:44.992: E/AndroidRuntime(693): at android.view.View.dispatchKeyEvent(View.java:7086)
1408-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
1508-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
1608-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
1708-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1358)
1808-27 18:30:44.992: E/AndroidRuntime(693): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1892)
1908-27 18:30:44.992: E/AndroidRuntime(693): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1369)
2008-27 18:30:44.992: E/AndroidRuntime(693): at android.app.Activity.dispatchKeyEvent(Activity.java:2356)
2108-27 18:30:44.992: E/AndroidRuntime(693): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1819)
2208-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3577)
2308-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3547)
2408-27 18:30:44.992: E/AndroidRuntime(693): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2797)
2508-27 18:30:44.992: E/AndroidRuntime(693): at android.os.Handler.dispatchMessage(Handler.java:99)
2608-27 18:30:44.992: E/AndroidRuntime(693): at android.os.Looper.loop(Looper.java:137)
2708-27 18:30:44.992: E/AndroidRuntime(693): at android.app.ActivityThread.main(ActivityThread.java:4745)
2808-27 18:30:44.992: E/AndroidRuntime(693): at java.lang.reflect.Method.invokeNative(Native Method)
2908-27 18:30:44.992: E/AndroidRuntime(693): at java.lang.reflect.Method.invoke(Method.java:511)
3008-27 18:30:44.992: E/AndroidRuntime(693): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
3108-27 18:30:44.992: E/AndroidRuntime(693): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
3208-27 18:30:44.992: E/AndroidRuntime(693): at dalvik.system.NativeStart.main(Native Method)
3308-27 18:30:44.992: E/AndroidRuntime(693): Caused by: java.lang.reflect.InvocationTargetException
3408-27 18:30:44.992: E/AndroidRuntime(693): at java.lang.reflect.Method.invokeNative(Native Method)
3508-27 18:30:44.992: E/AndroidRuntime(693): at java.lang.reflect.Method.invoke(Method.java:511)
3608-27 18:30:44.992: E/AndroidRuntime(693): at android.view.View$1.onClick(View.java:3586)
3708-27 18:30:44.992: E/AndroidRuntime(693): ... 24 more
3808-27 18:30:44.992: E/AndroidRuntime(693): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x5f
3908-27 18:30:44.992: E/AndroidRuntime(693): at android.content.res.Resources.getText(Resources.java:229)
4008-27 18:30:44.992: E/AndroidRuntime(693): at android.widget.TextView.setText(TextView.java:3620)
4108-27 18:30:44.992: E/AndroidRuntime(693): at com.punktegrenzen.MainActivity.Rechnen(MainActivity.java:51)
4208-27 18:30:44.992: E/AndroidRuntime(693): ... 27 more
4308-27 18:30:47.732: I/Process(693): Sending signal. PID: 693 SIG: 9
Das ist das was im log cat kam werde daraus aber nit schlau


Ps.: Bin erst morgen wieder online

— geändert am 27.08.2013, 20:42:30

Antworten
Christian
  • Forum-Beiträge: 307

27.08.2013, 22:05:41 via Website

Hi Lucas,

Fehler:
1android.content.res.Resources$NotFoundException: String resource ID #0x5f //<--- Fehlermeldung
23908-27 18:30:44.992: E/AndroidRuntime(693): at android.content.res.Resources.getText(Resources.java:229)
34008-27 18:30:44.992: E/AndroidRuntime(693): at android.widget.TextView.setText(TextView.java:3620)
44108-27 18:30:44.992: E/AndroidRuntime(693): at com.punktegrenzen.MainActivity.Rechnen(MainActivity.java:51) //<-- hier tritt sie in deinem Code auf

Lösung:
1feld1.setText(""+note1);
2feld2.setText(""+note2);
3feld3.setText(""+note3);
4feld4.setText(""+note4);
5feld5.setText(""+note5);
6feld6.setText(""+note6);


Ps.: ich weiß das note 6 sinnlos ist aber wenn ich sie weglasse habe ich ständig das gefühl das was fehl könnte ja die note 6 zeilen in der java activity rausnehmen und das edit text feld mit string füllen
Oder du sagst einfach das note6 = 0 ist weil die Rechnung ist eh immer 0,

Mfg Christian

Antworten
impjor
  • Forum-Beiträge: 1.793

27.08.2013, 23:10:29 via App

Christian H. hat die Lösung schon gepostet, vielleicht eine kurze Erklärung dazu: TextView kennt mehrere Methoden setText (sie sind überladen):

setText(CharSequence text)
setText(int resid)

Während du der ersten einen Text a lá "Hallo" übergeben kannst, erwartet die zweite einen int-Wert. Meistens (Immer) wird dafür eine konstante aus R.java wie z.B. R.string.meinString gewählt. So zeigt diese Methode dann nicht die Zahl an, sondern den String der in der entsprechenden strings.xml hinterlegt ist, da sich hinter R.string.blablablaa auch nur eine int-Konstante verbirgt.
LG

Liebe Grüße impjor.

Für ein gutes Miteinander: Unsere Regeln
Apps für jeden Einsatzzweck
Stellt eure App vor!

Antworten
Lucas Gregor
  • Forum-Beiträge: 16

28.08.2013, 15:14:32 via App

die app stürtzt jetzt nicht mehr ab, aber wenn ich in der app im feld gesammt punkte 100 oder mehr eingebe kommt bei den zahlen egal welche über hundert immer 95 im ersten 80 im zweiten usw. also ich gebe 120 ein aber die app gibt mir immer nur 95 etc. raus wenn der wert 0-99 ist wird mir überall 0 angezeigt
noch mal vielen dank für die bisherige hilfe

Antworten