Crash fixed

Stack trace: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.solovyev.android.calculator/org.solovyev.android.calculator.CalculatorDialogActivity}: java.lang.ArrayIndexOutOfBoundsException: length=3; index=100
This commit is contained in:
serso 2014-09-20 11:16:47 +02:00
parent e0ff803442
commit 40687b891e
3 changed files with 23 additions and 16 deletions

View File

@ -24,13 +24,12 @@ package org.solovyev.android.calculator;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.common.msg.Message;
import org.solovyev.common.msg.MessageType;
/** /**
* User: serso * User: serso
* Date: 11/17/12 * Date: 11/17/12
@ -70,14 +69,8 @@ public class FixableMessage implements Parcelable {
public FixableMessage(@Nonnull Message message) { public FixableMessage(@Nonnull Message message) {
this.message = message.getLocalizedMessage(); this.message = message.getLocalizedMessage();
int messageLevel = message.getMessageLevel().getMessageLevel(); final int messageLevel = message.getMessageLevel().getMessageLevel();
if (messageLevel < MessageType.info.getMessageLevel()) { this.messageType = CalculatorMessages.toMessageType(messageLevel);
this.messageType = MessageType.info;
} else if (messageLevel < MessageType.warning.getMessageLevel()) {
this.messageType = MessageType.warning;
} else {
this.messageType = MessageType.error;
}
this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode()); this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode());
} }

View File

@ -24,13 +24,12 @@ package org.solovyev.android.calculator;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import org.solovyev.common.msg.MessageLevel;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.solovyev.common.msg.MessageLevel;
import org.solovyev.common.msg.MessageType;
/** /**
* User: serso * User: serso
* Date: 1/20/13 * Date: 1/20/13
@ -93,7 +92,7 @@ public final class ParcelableDialogData implements DialogData, Parcelable {
@Nonnull @Nonnull
public static ParcelableDialogData fromParcel(@Nonnull Parcel in) { public static ParcelableDialogData fromParcel(@Nonnull Parcel in) {
final String message = in.readString(); final String message = in.readString();
final MessageType messageType = MessageType.values()[in.readInt()]; final MessageType messageType = CalculatorMessages.toMessageType(in.readInt());
final String title = in.readString(); final String title = in.readString();
return wrap(StringDialogData.newInstance(message, messageType, title)); return wrap(StringDialogData.newInstance(message, messageType, title));
} }

View File

@ -31,6 +31,10 @@ import java.util.Locale;
import java.util.MissingResourceException; import java.util.MissingResourceException;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import static org.solovyev.common.msg.MessageType.error;
import static org.solovyev.common.msg.MessageType.info;
import static org.solovyev.common.msg.MessageType.warning;
/** /**
* User: serso * User: serso
* Date: 9/20/12 * Date: 9/20/12
@ -94,6 +98,17 @@ public final class CalculatorMessages {
@Nonnull @Nonnull
public static CalculatorMessage newErrorMessage(@Nonnull String messageCode, @Nullable Object... parameters) { public static CalculatorMessage newErrorMessage(@Nonnull String messageCode, @Nullable Object... parameters) {
return new CalculatorMessage(messageCode, MessageType.error, parameters); return new CalculatorMessage(messageCode, error, parameters);
}
@Nonnull
static MessageType toMessageType(int messageLevel) {
if (messageLevel < info.getMessageLevel()) {
return info;
} else if (messageLevel < warning.getMessageLevel()) {
return warning;
}
return error;
} }
} }