Friday, 21 August 2015

Conversion to Dalvik format failed with error 1 in Android

When you are in the process of learning android development, you will encounter many issues on the way.

One such issue which i have encountered recently is the below error 


Dx 1 error; aborting
Conversion to Dalvik format failed with error 1

 
If you use the eclipse IDE, you will get a error message a portion that message is as below:

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

So, how to solve it?

Here it is.

1) Go to Project--> properties-->Java Build Path
2) Select Order and Export tab
3) Deselect the Android Private Libraries and Android Dependencies and click ok





 After doing the above steps, relaunch the application. 

 This time you should be happy seeing your application up and running :)

Friday, 9 January 2015

Applying custom colors in HSSF POI

Let us consider that we have to write a cell in excel and apply custom color for that.

In our example, we will apply some custom grey color,instead of the default grey color options available in Hssf POI.

Lets start by creating the workbook..


// creating work book..

HSSFWorkbook workbook = new HSSFWorkbook();

//defining the cell style

CellStyle customGrey = ExcelCreator.customHeaderGreyColor(workbook);


// creating the sheet..

HSSFSheet hssfSheet = workbook.createSheet("custom colors");
HSSFRow hssfRow = hssfSheet.createRow(0); // creating the 1st row

hssfRow.createCell(0).setCellValue("Welcome HSSF!");
hssfRow.getCell(0).setCellStyle(customGrey ); // applying the cell style to cell


Then in ExcelCreator file, we need to write the following methods..

//method to return the cell style

public static CellStyle customHeaderGreyColor(HSSFWorkbook workbook) {

        HSSFCellStyle headerStyle = workbook.createCellStyle();
        headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        headerStyle.setVerticalAlignment(headerStyle.VERTICAL_JUSTIFY);
        HSSFColor customGrey = getCustomColor(workbook, HSSFColor.GREY_80_PERCENT.index, (byte) 128, (byte) 128, (byte) 128);
        applyWhiteBorder(headerStyle);
        /* Applying custom grey color */
        headerStyle.setFillForegroundColor(customGrey.getIndex());
        headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
        return headerStyle;
    }

// method to get custom color

public static HSSFColor getCustomColor(HSSFWorkbook workbook, short colorIndex, byte r, byte g, byte b) {
        HSSFPalette palette = workbook.getCustomPalette();
        HSSFColor hssfColor = null;
        try {
            hssfColor = palette.findColor(r, g, b);
            if (hssfColor == null) {
                palette.setColorAtIndex(colorIndex, r, g, b);
                hssfColor = palette.getColor(colorIndex);
            }
        }
        catch (Exception e) {
        }

        return hssfColor;
    }

Friday, 12 December 2014

Disabling the previous dates in 'rich:calender' in jsf..

Add the following javascript code to the jsf file..




Then in jsf file where the <rich:calender> is defined, add the 'dayDisableFunction' attribute as below..