Android Open Source - Joetz-Android-V2 Error Converter

From Project

Back to project page Joetz-Android-V2.


The source code is released under:

GNU General Public License

If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.jens.myapplication.domain.converter;
//w w  w.j  av a2 s . c o m

import com.example.jens.myapplication.sam.JoetzApplication;

import java.util.Iterator;
import java.util.List;

 * Class to convert errors into a nice String
public class ErrorConverter {
     * This will convert all the errorIds into lines of text, explaining an error
     * @param errorIds All the resource IDs for error strings
     * @param itemName The name of the item that an error has occured on example:
     *                 "Email address is required" ({itemName} is required)
     * @return A string containing all the error messages
    public static String createErrorsString(List<Integer> errorIds, String itemName){
        String errorMsg = null;

        if (errorIds.size() > 1) {
            StringBuilder builder = new StringBuilder();
            Iterator<Integer> it = errorIds.iterator();
            while (it.hasNext()) {
                builder.append(buildErrorMsg(, itemName));
                if (it.hasNext()) {
            errorMsg = builder.toString();
        } else if(errorIds.size() == 1){
            errorMsg = buildErrorMsg(errorIds.get(0), itemName);
        return errorMsg;

     * @param resId Res ID of the error message to be displayed.
     * @param itemName Item corresponding to the error message (ex. "First name")
     * @return
    private static String buildErrorMsg(int resId, String itemName){
        if(itemName != null){
            return JoetzApplication.getContext().getString(resId, itemName);
            return JoetzApplication.getContext().getString(resId);

Java Source Code List