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 );
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
LayoutInflater factory = LayoutInflater.from( this );
if ( null != pairs ) {
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
LayoutInflater factory = LayoutInflater.from( this );
for ( DBUtils.HistoryPair pair : pairs ) {
TextView view =
(TextView)factory.inflate( pair.sourceLocal
? R.layout.chat_history_local
: R.layout.chat_history_remote,
null );
view.setText( pair.msg );
layout.addView( view );
for ( DBUtils.HistoryPair pair : pairs ) {
TextView view =
(TextView)factory.inflate( pair.sourceLocal
? R.layout.chat_history_local
: R.layout.chat_history_remote,
null );
view.setText( pair.msg );
layout.addView( view );
}
}
((Button)findViewById( R.id.send_button )).setOnClickListener( this );

View file

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