Android App aborts while sending receiving LinkedHashmap between activity

  • Replies:0
  • OpenNot stickiedUnanswered

Jan 23, 2014 7:26:57 AM via Website

I want to send and receive LinkedHashmap between activities. Below is my CODE but the application aborts when I try to pass/retrieve the map. Could anyone please help?

============
Sending Activity
============

1package com.moodswings.moodchart;
2
3import java.util.ArrayList;
4import java.util.LinkedHashMap;
5import java.util.List;
6import android.app.Activity;
7import android.content.Intent;
8import android.graphics.Color;
9import android.os.Bundle;
10import android.text.InputFilter;
11import android.text.InputType;
12import android.util.TypedValue;
13import android.view.Gravity;
14import android.view.View;
15import android.widget.*;
16
17public class MainActivity extends Activity
18{
19 ScrollView sv;
20 TableLayout myTableLayout;
21
22 Button submitButton;
23 Button resetButton;
24
25 LinkedHashMap<String, List<EditText>> dataMap = new LinkedHashMap<String, List<EditText>>();
26
27 [MENTION=439709]override[/MENTION]
28 public void onCreate(Bundle savedInstanceState)
29 {
30 super.onCreate(savedInstanceState);
31
32 sv = new ScrollView(this);
33 myTableLayout = new TableLayout (this);
34
35 submitButton = new Button(this);
36 resetButton = new Button(this);
37
38 drawScreen();
39
40 addListenerOnButton();
41 }
42
43 public void drawScreen()
44 {
45 String[] fctrdList = {"Mood","Aggr","Axty"};//,"Depr","Obsv", "Sleep"};
46
47 myTableLayout.removeAllViews();
48 sv.removeAllViews();
49
50 //myTableLayout.setBackgroundResource(R.drawable.background);
51
52 // rows
53 TableRow hrsRow = new TableRow(this);
54 TableRow buttonRow = new TableRow(this);
55
56 // margins
57 hrsRow.setPadding( 20,10,20,10);
58
59 // the buttons table layout
60 // purpose : right align for both buttons
61 TableLayout buttonsLayout = new TableLayout(this);
62 buttonRow.setPadding(20,50,40,0);
63
64 // the submit and reset buttons
65 submitButton.setText( "Submit");
66 resetButton.setText( "Reset");
67
68 buttonRow.addView( submitButton);
69 buttonRow.addView(resetButton);
70 buttonRow.setGravity(Gravity.RIGHT);
71
72 buttonsLayout.addView(buttonRow);
73
74 myTableLayout.addView(buttonsLayout);
75
76 //=============================================================
77
78 // time
79 TextView hrsV = new TextView(this);
80 hrsV.setText( "[00-04] [04-08] [08-12] [12-16] [16-20] [20-00]" );
81 hrsV.setTextSize(10);
82 hrsV.setTextColor(Color.BLACK );
83 hrsV.setGravity(Gravity.CENTER_HORIZONTAL);
84
85 hrsRow.addView(hrsV);
86 hrsRow.setGravity(Gravity.CENTER);
87
88 // the hours tablelayout
89 TableLayout hrsTableLayout = new TableLayout(this);
90 hrsTableLayout.addView(hrsRow);
91
92 // add the hours layout to the main one
93 myTableLayout.addView(hrsTableLayout);
94
95 /// the input rows
96 for(int j = 0; j < fctrdList.length; j++)
97 {
98 inputRow(myTableLayout, fctrdList[j]);
99 }
100 //
101
102 sv.addView(myTableLayout);
103
104 // set the screen content to table layout's
105 setContentView(sv);
106 }
107
108 public void inputRow( TableLayout tl, String label )
109 {
110 TableRow inputRow = new TableRow(this);
111 TextView tv = new TextView(this);
112 List<EditText> dataList = new ArrayList<EditText>();
113
114 // some margin
115 inputRow.setPadding(10,0,10,0);
116
117 tv.setText(label);
118 tv.setTextSize(10);
119 inputRow.addView(tv);
120
121 for(int i = 0; i < 2; i++)
122 {
123 EditText edit = new EditText(this);
124
125 edit.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
126 edit.setWidth(50);
127 edit.setHeight(50);
128 edit.setFilters(new InputFilter[] {new InputFilter.LengthFilter(2)});
129 edit.setInputType(InputType.TYPE_CLASS_NUMBER);
130 //edit.setId( 1 );
131 edit.setGravity(Gravity.LEFT);
132 inputRow.addView(edit);
133
134 dataList.add(edit);
135 }
136 dataMap.put(label, dataList);
137
138 tl.addView(inputRow);
139 }
140
141 public void addListenerOnButton() {
142
143 submitButton.setOnClickListener(new View.OnClickListener() {
144
145 [MENTION=439709]override[/MENTION]
146 public void onClick(View arg0) {
147
148 LinkedHashMap<String, List<String>> moodMap = new LinkedHashMap<String, List<String>>();
149
150 // populate List with EditText contents
151 for (LinkedHashMap.Entry<String, List<EditText>> entry : dataMap.entrySet()) {
152
153 List<EditText> edValues = entry.getValue();
154 //System.out.println("edValues size :" + edValues.size());
155
156 List<String> scaleList = new ArrayList<String>();
157 for(int a = 0; a < edValues.size(); a++)
158 {
159 EditText t = edValues.get(a);
160 String text = t.getText().toString();
161 //System.out.println("====== EditText :" + text);
162 scaleList.add(text);
163 }
164 moodMap.put(entry.getKey(), scaleList);
165 }
166
167 // =================
168 Bundle bundle = new Bundle();
169 bundle.putSerializable("factorsDataMap", moodMap);
170 Intent intent = new Intent(MainActivity.this, MoodSummary.class);
171 intent.putExtras(bundle);
172 startActivity(intent);
173
174 // =================
175 /*Intent intent = new Intent(MainActivity.this, MoodSummary.class);
176 intent.putExtra("map", moodMap);
177 startActivity(intent);*/
178 //==================
179 }
180 });
181 }
182}

============
Second Activity
============

1package com.moodswings.moodchart;
2
3import java.util.LinkedHashMap;
4import java.util.List;
5
6import android.app.Activity;
7import android.content.Intent;
8import android.os.Bundle;
9import android.widget.EditText;
10import android.widget.TextView;
11
12public class MoodSummary extends Activity {
13
14 public void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.mood_summary);
17
18 System.out.println("HashMapTest");
19
20 LinkedHashMap<String, List<String>> moodLnkMap = new LinkedHashMap<String, List<String>>();
21
22 Bundle bundle = this.getIntent().getExtras();
23 if(bundle != null){
24 moodLnkMap = (LinkedHashMap<String, List<String>>) bundle.getSerializable("factorsDataMap");
25
26 if(moodLnkMap.size() != 0)
27 {
28 System.out.println("moodMap size: " + moodLnkMap.size());
29 }
30 else
31 {
32 System.out.println("moodMap size: 0");
33 }
34 }
35 }
36
37}

========
The Logcat
========

101-22 17:58:16.345: D/MediaScannerService(198): done scanning volume internal 01-22 17:58:17.024: D/dalvikvm(116): GC_EXTERNAL_ALLOC freed 11169 objects / 521416 bytes in 81ms 01-22 17:58:17.294: D/dalvikvm(116): GC_EXPLICIT freed 1737 objects / 96240 bytes in 63ms 01-22 17:58:17.404: D/PackageParser(58): Scanning package: /data/app/vmdl52647.tmp 01-22 17:58:17.655: I/PackageManager(58): Removing non-system package:com.moodswings.moodchart 01-22 17:58:17.655: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:17.795: D/PackageManager(58): Scanning package com.moodswings.moodchart 01-22 17:58:17.795: I/PackageManager(58): Package com.moodswings.moodchart codePath changed from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk; Retaining data and using new 01-22 17:58:17.805: I/PackageManager(58): /data/app/com.moodswings.moodchart-2.apk changed; unpacking 01-22 17:58:17.815: D/installd(34): DexInv: --- BEGIN '/data/app/com.moodswings.moodchart-2.apk' --- 01-22 17:58:18.714: D/dalvikvm(257): DexOpt: load 112ms, verify 486ms, opt 28ms 01-22 17:58:18.784: D/installd(34): DexInv: --- END '/data/app/com.moodswings.moodchart-2.apk' (success) --- 01-22 17:58:18.784: W/PackageManager(58): Code path for pkg : com.moodswings.moodchart changing from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:18.794: W/PackageManager(58): Resource path for pkg : com.moodswings.moodchart changing from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:18.794: D/PackageManager(58): Activities: com.moodswings.moodchart.MainActivity com.moodswings.saqibchart.MoodSummary 01-22 17:58:18.804: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:18.924: I/installd(34): move /data/dalvik-cache/data@app@com.moodswings.moodchart-2.apk@classes.dex -> /data/dalvik-cache/data@app@com.moodswings.moodchart-2.apk@classes.dex 01-22 17:58:18.924: D/PackageManager(58): New package installed in /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:19.046: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:19.205: I/ActivityManager(58): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=258 uid=10028 gids={} 01-22 17:58:19.295: W/RecognitionManagerService(58): no available voice recognition services found 01-22 17:58:19.475: I/ActivityThread(258): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider 01-22 17:58:19.505: D/dalvikvm(157): GC_EXPLICIT freed 4255 objects / 257880 bytes in 436ms 01-22 17:58:19.625: D/dalvikvm(58): GC_EXPLICIT freed 9153 objects / 569160 bytes in 116ms 01-22 17:58:19.675: I/installd(34): unlink /data/dalvik-cache/data@app@com.moodswings.moodchart-1.apk@classes.dex 01-22 17:58:19.685: D/AndroidRuntime(205): Shutting down VM 01-22 17:58:19.695: D/jdwp(205): adbd disconnected 01-22 17:58:19.714: I/AndroidRuntime(205): NOTE: attach of thread 'Binder Thread #3' failed 01-22 17:58:20.214: D/AndroidRuntime(268): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 01-22 17:58:20.214: D/AndroidRuntime(268): CheckJNI is ON 01-22 17:58:20.344: D/AndroidRuntime(268): --- registering native functions --- 01-22 17:58:20.935: I/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.moodswings.moodchart/.MainActivity } 01-22 17:58:21.075: D/AndroidRuntime(268): Shutting down VM 01-22 17:58:21.085: I/ActivityManager(58): Start proc com.moodswings.moodchart for activity com.moodswings.moodchart/.MainActivity: pid=274 uid=10038 gids={} 01-22 17:58:21.094: D/jdwp(268): adbd disconnected 01-22 17:58:21.165: I/dalvikvm(268): JNI: AttachCurrentThread (from ???.???) 01-22 17:58:21.165: I/AndroidRuntime(268): NOTE: attach of thread 'Binder Thread #3' failed 01-22 17:58:21.454: E/jdwp(274): Failed sending reply to debugger: Broken pipe 01-22 17:58:21.454: D/dalvikvm(274): Debugger has detached; object registry had 1 entries 01-22 17:58:21.914: I/ActivityManager(58): Displayed activity com.moodswings.moodchart/.MainActivity: 843 ms (total 20356 ms) 01-22 17:58:21.914: I/ActivityManager(58): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 20358 ms (total 20358 ms) 01-22 17:58:32.785: D/KeyguardViewMediator(58): pokeWakelock(5000) 01-22 17:58:32.995: D/KeyguardViewMediator(58): pokeWakelock(5000) 01-22 17:58:33.354: I/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x273d28:0x273e34] in 495099 ns 01-22 17:58:33.424: I/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x29a378:0x29a540] in 676141 ns 01-22 17:58:35.995: D/dalvikvm(106): GC_FOR_MALLOC freed 1450 objects / 218728 bytes in 51ms 01-22 17:58:36.644: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:36.644: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:36.845: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 1992 objects / 136528 bytes in 62ms 01-22 17:58:37.715: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 544 objects / 27840 bytes in 53ms 01-22 17:58:37.944: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:37.944: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:40.515: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 317 objects / 20448 bytes in 94ms 01-22 17:58:40.676: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:40.676: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:43.195: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 356 objects / 22976 bytes in 74ms 01-22 17:58:43.345: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:43.376: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:44.665: I/ActivityManager(58): Starting activity: Intent { cmp=com.moodswings.moodchart/.MoodSummary (has extras) } 01-22 17:58:44.665: D/AndroidRuntime(274): Shutting down VM 01-22 17:58:44.665: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 01-22 17:58:44.685: E/AndroidRuntime(274): FATAL EXCEPTION: main 01-22 17:58:44.685: E/AndroidRuntime(274): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.moodswings.moodchart/com.moodswings.moodchart.MoodSummary}; have you declared this activity in your AndroidManifest.xml? 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Activity.startActivityForResult(Activity.java:2817) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Activity.startActivity(Activity.java:2923) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.moodswings.moodchart.MainActivity$1.onClick(MainActivity.java:172) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.view.View.performClick(View.java:2408) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.view.View$PerformClick.run(View.java:8816) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Handler.handleCallback(Handler.java:587) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Handler.dispatchMessage(Handler.java:92) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Looper.loop(Looper.java:123) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-22 17:58:44.685: E/AndroidRuntime(274): at java.lang.reflect.Method.invokeNative(Native Method) 01-22 17:58:44.685: E/AndroidRuntime(274): at java.lang.reflect.Method.invoke(Method.java:521) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-22 17:58:44.685: E/AndroidRuntime(274): at dalvik.system.NativeStart.main(Native Method) 01-22 17:58:44.695: W/ActivityManager(58): Force finishing activity com.moodswings.moodchart/.MainActivity 01-22 17:58:45.215: W/ActivityManager(58): Activity pause timeout for HistoryRecord{4a1851c8 com.moodswings.moodchart/.MainActivity} 01-22 17:58:45.314: I/ARMAssembler(58): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x2f9820:0x2f98dc] in 534098 ns 01-22 17:58:48.934: I/Process(274): Sending signal. PID: 274 SIG: 9 01-22 17:58:48.954: I/ActivityManager(58): Process com.moodswings.moodchart (pid 274) has died. 01-22 17:58:48.954: I/WindowManager(58): WIN DEATH: Window{4a2a9f40 com.moodswings.moodchart/com.moodswings.moodchart.MainActivity paused=false} 01-22 17:58:49.036: W/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 274 uid 10038 01-22 17:58:56.324: W/ActivityManager(58): Activity destroy timeout for HistoryRecord{4a1851c8 com.moodswings.moodchart/.MainActivity} 01-22 17:59:00.075: W/Process(58): Unable to open /proc/274/status