G
gbattine
Hi guys,
i need a disperate help.....i'm crazying on this problem and i don't
find an exit. I know this exception mean a bad casting...but can you
help me to know how solve it?
Without your help i'm not able to go on...
please help me....
Exception in thread "main" java.lang.ClassCastException: [B
at giu.princ.getBytes(princ.java:142)
at giu.princ.main(princ.java:158)
And my function is
package giu;
import java.io.BufferedReader;
import java.io.*;
import java.io.IOException;
import java.util.*;
public class princ {
private static String fileName = "Dato2.txt";
private static String file = "ris.txt";
private String geneid=null;
private static int row=0;
private static int numberOfNumericColumns=0;
private static int col=0;
Double[] values=new Double[numberOfNumericColumns];
String[]intest=null;
private ArrayList rows = new ArrayList();
Head h;
Riga r;
public boolean insRighe(Riga nuovo){
return rows.add(nuovo);
}
public List stampaRows(){
return rows;}
public Head stampaHead(){
return h;}
public void carica()throws IOException{
FileReader reader=new FileReader(fileName);
BufferedReader br = new BufferedReader(reader);
String line = null;
while ((line = br.readLine()) != null) {
line = line.replace (',', '.');
StringTokenizer st = new StringTokenizer(line);
numberOfNumericColumns = (st.countTokens()-1);
col=(numberOfNumericColumns+1);
//se siamo nella prima riga(contatore segna 0)
if(row==0){
intest=new String[col];
int j=0;
while(st.hasMoreTokens()){
intest[j]=(st.nextToken().trim());
j++;
}
/*for(int w=0;w<=intest.length-1;w++){
System.out.println(w+" "+intest[w]);
}*/
//STAMPA LA RIGA HEAD ALL'INIZIO DELL'OUTPUT
h=new Head(intest);//crei l'oggetto head
String []qa=h.getHvalues();
String asd="";
for(int i=0;i<=qa.length-1;i++){
asd=asd.concat(qa+" ");
}
System.out.println("head "+asd);//stampo contenuto dell' head
row=1;
}//fine if
else
{
Double[] values=new Double[numberOfNumericColumns];
int z=0;
geneid=st.nextToken();
while (st.hasMoreTokens()) {
String app=st.nextToken();
values[z]=Double.valueOf(app);
z++;
}
r=new Riga(geneid,values); //crei l'oggetto riga
System.out.println("riga");
System.out.println(r.getgeneid());
values=r.getvalues();
for(int e=0;e<=values.length-1;e++){
System.out.println(values[e]);
}
insRighe(r); //aggiungi
}
row++;
}
}
public byte[] getBytes(){
byte middlerow=' ';
byte endrow=';';
byte[] data;
Vector temp=new Vector(100000);
int i=0;
String g=null;
Riga r;
Double val[];
while(i<intest.length){
temp.addElement(intest.getBytes());
temp.addElement(Byte.valueOf(middlerow));
i++;
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for(int l=0;l<rows.size()-1;l++){
r=(Riga)rows.get(l);
g=r.getgeneid();
temp.addElement(g.getBytes());
temp.addElement(Byte.valueOf(middlerow));
val=r.getvalues();
byte[] tempByte1;
for(int e=0;e<=val.length-1;e++){
//Returns a string representation of the double argument.
tempByte1 = Double.toString(val[e]).getBytes();
System.out.println("la soluzione e"+tempByte1);
for (int j = 0; j >< tempByte1.length; j++) {
temp.addElement(Byte.valueOf(tempByte1[j]));
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("la soluzione 4e"+tempByte1);
}
}
data=new byte[temp.size()];
System.out.println("la soluzione 2e"+data);
for (int t=0;t<temp.size()-1;t++)
data[t]=(((Byte)temp.elementAt(t)).byteValue());
System.out.println("la soluzione nuova");
System.out.println(temp);
/*for (int k=0;k<=temp.size()-1;k++){
System.out.println(k+ " temp "+temp.get(k));
}*/
return data;
}
public static void main(String[] args) throws IOException {
byte x[];
String totale=null;
princ p=new princ();
p.carica();
System.out.println("Dati caricati");
x=p.getBytes();
System.out.println("Byte convertiti");
BufferedWriter out = new BufferedWriter(new FileWriter(file));; //
define the output stream
for(int i=0;i<=x.length;i++){
System.out.println(x);
//out.writeByte
//out.write(" ");
} //write the array of bytes to file
}
}
i need a disperate help.....i'm crazying on this problem and i don't
find an exit. I know this exception mean a bad casting...but can you
help me to know how solve it?
Without your help i'm not able to go on...
please help me....
Exception in thread "main" java.lang.ClassCastException: [B
at giu.princ.getBytes(princ.java:142)
at giu.princ.main(princ.java:158)
And my function is
package giu;
import java.io.BufferedReader;
import java.io.*;
import java.io.IOException;
import java.util.*;
public class princ {
private static String fileName = "Dato2.txt";
private static String file = "ris.txt";
private String geneid=null;
private static int row=0;
private static int numberOfNumericColumns=0;
private static int col=0;
Double[] values=new Double[numberOfNumericColumns];
String[]intest=null;
private ArrayList rows = new ArrayList();
Head h;
Riga r;
public boolean insRighe(Riga nuovo){
return rows.add(nuovo);
}
public List stampaRows(){
return rows;}
public Head stampaHead(){
return h;}
public void carica()throws IOException{
FileReader reader=new FileReader(fileName);
BufferedReader br = new BufferedReader(reader);
String line = null;
while ((line = br.readLine()) != null) {
line = line.replace (',', '.');
StringTokenizer st = new StringTokenizer(line);
numberOfNumericColumns = (st.countTokens()-1);
col=(numberOfNumericColumns+1);
//se siamo nella prima riga(contatore segna 0)
if(row==0){
intest=new String[col];
int j=0;
while(st.hasMoreTokens()){
intest[j]=(st.nextToken().trim());
j++;
}
/*for(int w=0;w<=intest.length-1;w++){
System.out.println(w+" "+intest[w]);
}*/
//STAMPA LA RIGA HEAD ALL'INIZIO DELL'OUTPUT
h=new Head(intest);//crei l'oggetto head
String []qa=h.getHvalues();
String asd="";
for(int i=0;i<=qa.length-1;i++){
asd=asd.concat(qa+" ");
}
System.out.println("head "+asd);//stampo contenuto dell' head
row=1;
}//fine if
else
{
Double[] values=new Double[numberOfNumericColumns];
int z=0;
geneid=st.nextToken();
while (st.hasMoreTokens()) {
String app=st.nextToken();
values[z]=Double.valueOf(app);
z++;
}
r=new Riga(geneid,values); //crei l'oggetto riga
System.out.println("riga");
System.out.println(r.getgeneid());
values=r.getvalues();
for(int e=0;e<=values.length-1;e++){
System.out.println(values[e]);
}
insRighe(r); //aggiungi
}
row++;
}
}
public byte[] getBytes(){
byte middlerow=' ';
byte endrow=';';
byte[] data;
Vector temp=new Vector(100000);
int i=0;
String g=null;
Riga r;
Double val[];
while(i<intest.length){
temp.addElement(intest.getBytes());
temp.addElement(Byte.valueOf(middlerow));
i++;
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for(int l=0;l<rows.size()-1;l++){
r=(Riga)rows.get(l);
g=r.getgeneid();
temp.addElement(g.getBytes());
temp.addElement(Byte.valueOf(middlerow));
val=r.getvalues();
byte[] tempByte1;
for(int e=0;e<=val.length-1;e++){
//Returns a string representation of the double argument.
tempByte1 = Double.toString(val[e]).getBytes();
System.out.println("la soluzione e"+tempByte1);
for (int j = 0; j >< tempByte1.length; j++) {
temp.addElement(Byte.valueOf(tempByte1[j]));
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("la soluzione 4e"+tempByte1);
}
}
data=new byte[temp.size()];
System.out.println("la soluzione 2e"+data);
for (int t=0;t<temp.size()-1;t++)
data[t]=(((Byte)temp.elementAt(t)).byteValue());
System.out.println("la soluzione nuova");
System.out.println(temp);
/*for (int k=0;k<=temp.size()-1;k++){
System.out.println(k+ " temp "+temp.get(k));
}*/
return data;
}
public static void main(String[] args) throws IOException {
byte x[];
String totale=null;
princ p=new princ();
p.carica();
System.out.println("Dati caricati");
x=p.getBytes();
System.out.println("Byte convertiti");
BufferedWriter out = new BufferedWriter(new FileWriter(file));; //
define the output stream
for(int i=0;i<=x.length;i++){
System.out.println(x);
//out.writeByte
//out.write(" ");
} //write the array of bytes to file
}
}