클래스 설명
A -> B -> C
A: 버튼 눌렀을 경우 Hashtable을 B 액티비티로 보냄
B: TabActivity로써 A에서 받은 intent를 get해서 다시 C로 인텐트를 넘겨줌( C는 B의 첫화면임 )
c: B에서 받은 인텐트를 뽑아서 Hashtable의 size를 출력
코드
A클래스)
Intent i = new Intent( FastRoadSearchActivity.this, TransOutCityActivity.class );
i.putExtra( "outbus", ( Hashtable )resultHash.get( "outbus" ) );
startActivity( i );
B클래스)
Intent intent;
i = getIntent();
intent = new Intent( this, Trans1Activity.class);
intent.putExtra( "outbus", i.getSerializableExtra("outbus") );
spec = tabHost.newTabSpec("outbus").setIndicator( "시외",
getResources().getDrawable(R.drawable.icon ))
.setContent(intent);
tabHost.addTab(spec);
C클래스)
Hashtable hash = ( Hashtable ) getIntent().getSerializableExtra( "outbut" );
System.out.println( "size" + hash.size() );
C클래스에서 size를 출력하면 널포인터 익셉션이 호출됩니다.
왜 그런건가요?
도저히 안되서 질문드릅니다...
해결했습니다
자답입니다.
Serializable s = getIntent().getSerializableExtra( "outbus" );
if( s != null ) {
Hashtable hash = new Hashtable( (HashMap) s );
System.out.println( "size" + hash.size() );
}
else {
System.out.println( "null" );
}
이 코드로 해결했습니다. 제가 C클래스에서 outbus key도 오타군요 outbut이렇게 해놨고
그리고 null체크를 해줘야 하고 여기서 캐스트를 HashMap으로 바꾼 뒤 다시 생성자에 넣어야 제대로 캐스트가 되네요.
구글링 하면서 외국인이 올려놓은 질답을 보고 알았네요...
ㅜㅜㅜㅜ