[Java for Android App Development] HeidiK:
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

============

package com.moodswings.moodchart;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.*;

public class MainActivity extends Activity
{
ScrollView sv;
TableLayout myTableLayout;

Button submitButton;
Button resetButton;

LinkedHashMap<String, List<EditText>> dataMap = new LinkedHashMap<String, List<EditText>>();

[MENTION=439709]override[/MENTION]
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

sv = new ScrollView(this);
myTableLayout = new TableLayout (this);

submitButton = new Button(this);
resetButton = new Button(this);

drawScreen();

addListenerOnButton();
}

public void drawScreen()
{
String[] fctrdList = {"Mood","Aggr","Axty"};//,"Depr","Obsv", "Sleep"};

myTableLayout.removeAllViews();
sv.removeAllViews();

//myTableLayout.setBackgroundResource(R.drawable.background);

// rows
TableRow hrsRow = new TableRow(this);
TableRow buttonRow = new TableRow(this);

// margins
hrsRow.setPadding( 20,10,20,10);

// the buttons table layout
// purpose : right align for both buttons
TableLayout buttonsLayout = new TableLayout(this);
buttonRow.setPadding(20,50,40,0);

// the submit and reset buttons
submitButton.setText( "Submit");
resetButton.setText( "Reset");

buttonRow.addView( submitButton);
buttonRow.addView(resetButton);
buttonRow.setGravity(Gravity.RIGHT);

buttonsLayout.addView(buttonRow);

myTableLayout.addView(buttonsLayout);

//=============================================================

// time
TextView hrsV = new TextView(this);
hrsV.setText( "[00-04] [04-08] [08-12] [12-16] [16-20] [20-00]" );
hrsV.setTextSize(10);
hrsV.setTextColor(Color.BLACK );
hrsV.setGravity(Gravity.CENTER_HORIZONTAL);

hrsRow.addView(hrsV);
hrsRow.setGravity(Gravity.CENTER);

// the hours tablelayout
TableLayout hrsTableLayout = new TableLayout(this);
hrsTableLayout.addView(hrsRow);

// add the hours layout to the main one
myTableLayout.addView(hrsTableLayout);

/// the input rows
for(int j = 0; j < fctrdList.length; j++)
{
inputRow(myTableLayout, fctrdList[j]);
}
//

sv.addView(myTableLayout);

// set the screen content to table layout's
setContentView(sv);
}

public void inputRow( TableLayout tl, String label )
{
TableRow inputRow = new TableRow(this);
TextView tv = new TextView(this);
List<EditText> dataList = new ArrayList<EditText>();

// some margin
inputRow.setPadding(10,0,10,0);

tv.setText(label);
tv.setTextSize(10);
inputRow.addView(tv);

for(int i = 0; i < 2; i++)
{
EditText edit = new EditText(this);

edit.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
edit.setWidth(50);
edit.setHeight(50);
edit.setFilters(new InputFilter[] {new InputFilter.LengthFilter(2)});
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
//edit.setId( 1 );
edit.setGravity(Gravity.LEFT);
inputRow.addView(edit);

dataList.add(edit);
}
dataMap.put(label, dataList);

tl.addView(inputRow);
}

public void addListenerOnButton() {

submitButton.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {

LinkedHashMap<String, List<String>> moodMap = new LinkedHashMap<String, List<String>>();

// populate List with EditText contents
for (LinkedHashMap.Entry<String, List<EditText>> entry : dataMap.entrySet()) {

List<EditText> edValues = entry.getValue();
//System.out.println("edValues size :" + edValues.size());

List<String> scaleList = new ArrayList<String>();
for(int a = 0; a < edValues.size(); a++)
{
EditText t = edValues.get(a);
String text = t.getText().toString();
//System.out.println("====== EditText :" + text);
scaleList.add(text);
}
moodMap.put(entry.getKey(), scaleList);
}

// =================
Bundle bundle = new Bundle();
bundle.putSerializable("factorsDataMap", moodMap);
Intent intent = new Intent(MainActivity.this, MoodSummary.class);
intent.putExtras(bundle);
startActivity(intent);

// =================
/*Intent intent = new Intent(MainActivity.this, MoodSummary.class);
intent.putExtra("map", moodMap);
startActivity(intent);*/
//==================
}
});
}
}

============

Second Activity

============

package com.moodswings.moodchart;

import java.util.LinkedHashMap;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class MoodSummary extends Activity {

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mood_summary);

System.out.println("HashMapTest");

LinkedHashMap<String, List<String>> moodLnkMap = new LinkedHashMap<String, List<String>>();

Bundle bundle = this.getIntent().getExtras();
if(bundle != null){
moodLnkMap = (LinkedHashMap<String, List<String>>) bundle.getSerializable("factorsDataMap");

if(moodLnkMap.size() != 0)
{
System.out.println("moodMap size: " + moodLnkMap.size());
}
else
{
System.out.println("moodMap size: 0");
}
}
}

}

========

The Logcat

========

01-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