fix NPE: if there's no history string don't try to split it.

This commit is contained in:
Andy2 2011-02-18 17:44:23 -08:00
parent d2fda267e5
commit 0726cefb10
2 changed files with 23 additions and 17 deletions

View file

@ -51,17 +51,19 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
} }
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path ); DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path );
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history ); if ( null != pairs ) {
LayoutInflater factory = LayoutInflater.from( this ); LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
LayoutInflater factory = LayoutInflater.from( this );
for ( DBUtils.HistoryPair pair : pairs ) { for ( DBUtils.HistoryPair pair : pairs ) {
TextView view = TextView view =
(TextView)factory.inflate( pair.sourceLocal (TextView)factory.inflate( pair.sourceLocal
? R.layout.chat_history_local ? R.layout.chat_history_local
: R.layout.chat_history_remote, : R.layout.chat_history_remote,
null ); null );
view.setText( pair.msg ); view.setText( pair.msg );
layout.addView( view ); layout.addView( view );
}
} }
((Button)findViewById( R.id.send_button )).setOnClickListener( this ); ((Button)findViewById( R.id.send_button )).setOnClickListener( this );

View file

@ -164,7 +164,7 @@ public class DBUtils {
saveSummary( context, file, summary ); saveSummary( context, file, summary );
} }
return summary; return summary;
} } // getSummary
public static void saveSummary( Context context, String path, public static void saveSummary( Context context, String path,
GameSummary summary ) GameSummary summary )
@ -482,13 +482,17 @@ public class DBUtils {
public static HistoryPair[] getChatHistory( Context context, String path ) public static HistoryPair[] getChatHistory( Context context, String path )
{ {
HistoryPair[] result = null;
final String localPrefix = context.getString( R.string.chat_local_id ); final String localPrefix = context.getString( R.string.chat_local_id );
String[] msgs = getChatHistoryStr( context, path ).split( "\n" ); String history = getChatHistoryStr( context, path );
HistoryPair[] result = new HistoryPair[msgs.length]; if ( null != history ) {
for ( int ii = 0; ii < result.length; ++ii ) { String[] msgs = history.split( "\n" );
String msg = msgs[ii]; result = new HistoryPair[msgs.length];
boolean isLocal = msg.startsWith( localPrefix ); for ( int ii = 0; ii < result.length; ++ii ) {
result[ii] = new HistoryPair( msg, isLocal ); String msg = msgs[ii];
boolean isLocal = msg.startsWith( localPrefix );
result[ii] = new HistoryPair( msg, isLocal );
}
} }
return result; return result;
} }