dimanche 2 novembre 2014

Java.lang.IndexOutOfBoundsException: Index: 1, Size: 1


Vote count:

-1




i have result in my program :


P_CUP;EI-BANK PUNDI INDONESIA;;CU-156001 CUP;20141023;113322;30;0210;6232032010000203640;0.00;0.00;7000;112132;741160;APP;00;00;000456;;EK01101;;;JAKARTA;


Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at id.co.ptap.text.ParseText.main(ParseText.java:370)


and this is main code who i make:



public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
ParseText parseText = new ParseText();
String path = cfg.getPathP_CUP();
String write = cfg.getfileP_CUP();
int dte = Integer.parseInt(cfg.getsetDate());
String dd = String.valueOf(dte-1);
SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
Date dt = new Date();
if(dte == 0){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
Date sbl = cal.getTime();

path = path.replaceAll("#yyMMdd#", sdf.format(sbl));
write = write.replaceAll("#yyMMdd#", sdf.format(sbl));
parseText.getKey(cfg.getloadP_CUP());
} else {
String dte1 = String.valueOf(dte);
String yy = dte1.substring(0, 2);
String mm = dte1.substring(2, 4);
String dde = dte1.substring(4, 6);

if(!dde.equals("01")){
path = path.replaceAll("#yyMMdd#", dd);
write = write.replaceAll("#yyMMdd#", dd);
}
else if(Integer.parseInt(yy) % 4 == 0){
if(mm.equals("01") && dde.equals("01")){
mm = mm.replace("01", "12");
dde = dde.replace("01", "31");
} else if(mm.equals("02") && dde.equals("01")){
mm = mm.replace("02", "01");
dde = dde.replace("01", "31");
} else if(mm.equals("03") && dde.equals("01")){
mm = mm.replace("03", "02");
dde = dde.replace("01", "29");
} else if(mm.equals("04") && dde.equals("01")){
mm = mm.replace("04", "03");
dde = dde.replace("01", "31");
}else if(mm.equals("05") && dde.equals("01")){
mm = mm.replace("05", "04");
dde = dde.replace("01", "30");
}else if(mm.equals("06") && dde.equals("01")){
mm = mm.replace("06", "05");
dde = dde.replace("01", "31");
}else if(mm.equals("07") && dde.equals("01")){
mm = mm.replace("07", "06");
dde = dde.replace("01", "30");
}else if(mm.equals("08") && dde.equals("01")){
mm = mm.replace("08", "07");
dde = dde.replace("01", "31");
}else if(mm.equals("09") && dde.equals("01")){
mm = mm.replace("09", "08");
dde = dde.replace("01", "31");
}else if(mm.equals("10") && dde.equals("01")){
mm = mm.replace("10", "09");
dde = dde.replace("01", "30");
}else if(mm.equals("11") && dde.equals("01")){
mm = mm.replace("11", "10");
dde = dde.replace("01", "31");
}else if(mm.equals("12") && dde.equals("01")){
mm = mm.replace("12", "11");
dde = dde.replace("01", "30");
}
} else{
if(mm.equals("01") && dde.equals("01")){
mm = mm.replace("01", "12");
dde = dde.replace("01", "31");
} else if(mm.equals("02") && dde.equals("01")){
mm = mm.replace("02", "01");
dde = dde.replace("01", "31");
} else if(mm.equals("03") && dde.equals("01")){
mm = mm.replace("03", "02");
dde = dde.replace("01", "28");
} else if(mm.equals("04") && dde.equals("01")){
mm = mm.replace("04", "03");
dde = dde.replace("01", "31");
}else if(mm.equals("05") && dde.equals("01")){
mm = mm.replace("05", "04");
dde = dde.replace("01", "30");
}else if(mm.equals("06") && dde.equals("01")){
mm = mm.replace("06", "05");
dde = dde.replace("01", "31");
}else if(mm.equals("07") && dde.equals("01")){
mm = mm.replace("07", "06");
dde = dde.replace("01", "30");
}else if(mm.equals("08") && dde.equals("01")){
mm = mm.replace("08", "07");
dde = dde.replace("01", "31");
}else if(mm.equals("09") && dde.equals("01")){
mm = mm.replace("09", "08");
dde = dde.replace("01", "31");
}else if(mm.equals("10") && dde.equals("01")){
mm = mm.replace("10", "09");
dde = dde.replace("01", "30");
}else if(mm.equals("11") && dde.equals("01")){
mm = mm.replace("11", "10");
dde = dde.replace("01", "31");
}else if(mm.equals("12") && dde.equals("01")){
mm = mm.replace("12", "11");
dde = dde.replace("01", "30");
}
}
String dte2 = yy+mm+dde;
path = path.replaceAll("#yyMMdd#",dte2);
write = write.replaceAll("#yyMMdd#", dte2);
parseText.getKey(cfg.getloadP_CUP());
}

parseText.getData(path, true, true, false);
FileWriter fw = new FileWriter(write);

BufferedWriter bw = new BufferedWriter(fw);
String first = "P_CUP";
List<String> allHeader = new ArrayList<String>();
for (int i = 0; i < parseText.getListAllHeader().size(); i++) {
ContainerBean container = parseText.getListAllHeader().get(i);
String strHeader = "";

List<DataBean> listData = container.getHeader();
for (int j = 0; j < listData.size(); j++) {

if(listData.get(j).getKey().equals("RETENSI") || listData.get(j).getKey().equals("LAPORAN") || listData.get(j).getKey().equals("FREKWENSI")){
strHeader = "";
}
else if(listData.get(j).getKey().equals("HALAMAN")){
strHeader = strHeader.replace(listData.get(j).getValue(), "")+";";
}
else if(listData.get(j).getKey().equals("ACQUIRER")){
strHeader = listData.get(j).getValue()+";";
}
else{
strHeader = strHeader + listData.get(j).getValue()+ ";";
}
}
allHeader.add(strHeader);
}

String x = "";
int count = 0;
boolean ketemu = false;
for (int i = 0; i < parseText.getListAllBody().size(); i++) {
ContainerBean container = parseText.getListAllBody().get(i);
String strBody = "";

List<DataBean> listData = container.getDetail();
for (int j = 0; j < listData.size(); j++) {
if(listData.get(j).getKey().equals("NO")){
strBody = "";
}
else if(listData.get(j).getKey().equals("TANGGAL")){
strBody += "20" + listData.get(j).getValue().substring(6, 8);
strBody += listData.get(j).getValue().substring(3, 5);
strBody += listData.get(j).getValue().substring(0, 2) + ";";
}
else if(listData.get(j).getKey().equals("JAM")){
strBody += listData.get(j).getValue().replace(":", "") + ";";
}
else if(listData.get(j).getKey().equals("AMOUNT")){
strBody += listData.get(j).getValue().replace(",", "") + ";";
}
else if(listData.get(j).getKey().equals("PENERIMA TRANSFER")){
strBody += listData.get(j).getValue().replace("-", "") + ";";
}

else{
strBody = strBody + listData.get(j).getValue().trim() + ";";
}
if (listData.get(j).getKey().equals("NO")) {
if (listData.get(j).getValue().trim().equals("1")) {
ketemu = true;
}
}
}
x = first+";"+allHeader.get(count) + strBody + "\n";
bw.write(x);
System.out.println(x);


if (ketemu) {
count++;
ketemu = false;
}

}

bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public void getKey(String propertiesFile) throws IOException {
Properties prop = new Properties();
InputStream input = new FileInputStream(propertiesFile);

prop.load(input);

String strHeader = prop.getProperty("header");
setHeaderKey(strHeader.split(","));
for (int i = 0; i < getHeaderKey().length; i++) {
getHeaderKey()[i] = getHeaderKey()[i].trim();
}
setBeginBody(prop.getProperty("body.begin"));
setEndBody(prop.getProperty("body.end"));
setBodyLine(Integer.parseInt(prop.getProperty("body.line")));

for (int i = 1; i <= getBodyLine(); i++) {
String strTmp = prop.getProperty("body.title" + i);
String[] arrTmp = strTmp.split(",");
for (int j = 0; j < arrTmp.length; j++) {
arrTmp[j] = arrTmp[j].trim();
}
getBodyKey().add(arrTmp);

strTmp = prop.getProperty("body.title" + i + ".posstart");
arrTmp = strTmp.split(",");
int[] iBodyPos = new int[arrTmp.length];
for (int j = 0; j < arrTmp.length; j++) {
iBodyPos[j] = Integer.parseInt(arrTmp[j].trim());
}
getBodyPos().add(iBodyPos);
}

String strFooter = prop.getProperty("footer");
setFooterKey(strFooter.split(","));
for (int i = 0; i < getFooterKey().length; i++) {
getFooterKey()[i] = getFooterKey()[i].trim();
}
}

public boolean isHeader(String str) {
boolean retVal = false;
for (int i = 0; i < getHeaderKey().length; i++) {
if (str.contains(getHeaderKey()[i])) {
retVal = true;
break;
}
}
return retVal;
}
public boolean isFooter(String str) {
boolean retVal = false;
for (int i = 0; i < getFooterKey().length; i++) {
if (str.contains(getFooterKey()[i])) {
retVal = true;
break;
}
}
return retVal;
}

public boolean isLine(String str) {
if (str.trim().endsWith("--+")) {
return true;
}
else return false;
}

public boolean isTitle(String str) {
boolean retVal = false;
int count = 0;
for (int i = 0; i < getBodyKey().size(); i++) {
for (int j = 0; j < getBodyKey().get(i).length; j++) {
if (str.contains(getBodyKey().get(i)[j])) {
count++;
}
if (count > 3) {
retVal = true;
break;
}
}
}
return retVal;
}

public void getData(String dataFile, boolean getHeader, boolean getBody, boolean getFooter) throws IOException {
BufferedReader br = null;

String strLine;
br = new BufferedReader(new FileReader(dataFile));

DataBean dataBean = null;

int headerLength = 0;
int footerLength = 0;
boolean procHeader = true;
boolean procBody = false;
boolean procFooter = false;
int totLine = 0;
int totCols = 0;
if (!getHeader) {
procHeader = false;
}
while ((strLine = br.readLine()) != null) {
if (getHeader && !procBody && !procFooter) {
for (int i = 0; i < getHeaderKey().length; i++) {
if (strLine.contains(getHeaderKey()[i])) {
String data = strLine;
dataBean = new DataBean();
dataBean.setKey(getHeaderKey()[i]);

int posX = data.indexOf(getHeaderKey()[i]);
data = data.substring(posX);
posX = data.indexOf(":");
if (posX > (getHeaderKey()[i].length() * 2) || posX == -1) continue;
data = data.substring(posX + 2).trim();

int posY = data.indexOf(" ");

if (posY == -1) {
data = data.trim();
} else {
data = data.substring(0, posY);
}

dataBean.setValue(data);
getListHeader().add(dataBean);
headerLength++;
procHeader = true;
}
if (headerLength == getHeaderKey().length) {
headerLength = 0;
ContainerBean container = new ContainerBean();
container.setHeader(getListHeader());
getListAllHeader().add(container);
getListHeader().clear();
procHeader = false;
}
}
}
if (getBody && !procHeader) {
if (strLine.trim().startsWith(getEndBody()) && procBody && totCols == 0) {
procBody = false;
totLine = 0;
continue;
}
if (strLine.trim().startsWith(getBeginBody())) {
procBody = true;
totLine = 0;
continue;
}
if (procBody) {
String data = strLine;
if (isTitle(data) || isHeader(data) || isFooter(data) || isLine(data)) {
continue;
}

for (int i = 0; i < getBodyKey().get(totLine).length; i++ ) {
dataBean = new DataBean();
dataBean.setKey(getBodyKey().get(totLine)[i]);
if (i == getBodyKey().get(totLine).length -1) {
dataBean.setValue(data.substring(getBodyPos().get(totLine)[i]));
}
else {
dataBean.setValue(data.substring(getBodyPos().get(totLine)[i], getBodyPos().get(totLine)[i + 1]).trim());
}
totCols++;
getListBody().add(dataBean);
}
if (totLine == (getBodyLine() - 1)) {
ContainerBean container = new ContainerBean();
container.setDetail(getListBody());
getListAllBody().add(container);
getListBody().clear();
totCols = 0;
totLine = 0;
}
else {
totLine++;
}

}
}
if (getFooter && !procHeader && !procBody) {
for (int i = 0; i < getFooterKey().length; i++) {
if (strLine.contains(getFooterKey()[i])) {
String data = strLine;
dataBean = new DataBean();
dataBean.setKey(getFooterKey()[i]);

int posX = data.indexOf(getFooterKey()[i]);
data = data.substring(posX);
posX = data.indexOf(": ");
if (posX > (getFooterKey()[i].length() * 2) || posX == -1) continue;
data = data.substring(posX + 2).trim();

int posY = data.indexOf(" ");

if (posY == -1) {
data = data.trim();
} else {
data = data.substring(0, posY);
}

dataBean.setValue(data);
getListFooter().add(dataBean);
footerLength++;
procFooter = true;
}
if (footerLength == getFooterKey().length) {
footerLength = 0;
ContainerBean container = new ContainerBean();
container.setFooter(getListFooter());
getListAllFooter().add(container);
getListFooter().clear();
procFooter = false;
}
}
}

}

br.close();


help me for this problem. what should i do ?



asked 1 min ago







Java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

Aucun commentaire:

Enregistrer un commentaire