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,6 +51,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
} }
DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path ); DBUtils.HistoryPair[] pairs = DBUtils.getChatHistory( this, m_path );
if ( null != pairs ) {
LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history ); LinearLayout layout = (LinearLayout)findViewById( R.id.chat_history );
LayoutInflater factory = LayoutInflater.from( this ); LayoutInflater factory = LayoutInflater.from( this );
@ -63,6 +64,7 @@ public class ChatActivity extends XWActivity implements View.OnClickListener {
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,14 +482,18 @@ 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 ) {
String[] msgs = history.split( "\n" );
result = new HistoryPair[msgs.length];
for ( int ii = 0; ii < result.length; ++ii ) { for ( int ii = 0; ii < result.length; ++ii ) {
String msg = msgs[ii]; String msg = msgs[ii];
boolean isLocal = msg.startsWith( localPrefix ); boolean isLocal = msg.startsWith( localPrefix );
result[ii] = new HistoryPair( msg, isLocal ); result[ii] = new HistoryPair( msg, isLocal );
} }
}
return result; return result;
} }