#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Data Structure Construction


    Hello,

    I'm trying to fill a List<String>, named overlappedGrid, from another List<String>, named listGrid. I'm facing an exception:

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type
    required: variable
    found: value
    at arab2004_d.ProcessingLayer.printShape(Arab2004_D.java:101)
    at arab2004_d.Arab2004_D.main(Arab2004_D.java:30)
    Java Result: 1

    Here is my source code (the exception line is commented "here is the exception"):

    package arab2004_d;

    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.LinkedList;
    import java.util.List;

    /**
    *
    * @author dell
    */
    public class Arab2004_D {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws IOException {
    // TODO code application logic here
    ReadingLayer r = new ReadingLayer();
    r.read("overlap.in.txt");
    ProcessingLayer p = new ProcessingLayer();
    List<String> grid = p.printShape(r.allGrids.get(0));
    for(int i = 0;i < grid.size();i++){
    System.out.println(grid.get(i));
    }
    }

    }
    class ReadingLayer {
    List<String[]> allDimensions = new LinkedList<String[]>();
    List<String[][]> allGrids = new LinkedList<String[][]>();
    void read(String filePath) throws FileNotFoundException, IOException{
    BufferedReader reader = new BufferedReader(new FileReader(filePath));
    String[] dimensions = reader.readLine().split(" ");
    while(!dimensions[0].equals("0") && !dimensions[1].equals("0")){
    allDimensions.add(dimensions);
    String[][] grid = new String[Integer.valueOf(dimensions[0])][Integer.valueOf(dimensions[1])];
    for(int i = 0;i < Integer.valueOf(dimensions[0]);i++){
    String line = reader.readLine();
    for(int j = 0;j < Integer.valueOf(dimensions[1]);j++){
    grid[i][j] = String.valueOf(line.charAt(j));
    }
    }
    allGrids.add(grid);
    dimensions = reader.readLine().split(" ");
    }
    }
    }
    class ProcessingLayer {
    int index;
    boolean calculateMaxShared(List<String> grid){
    boolean test = false;
    int size = grid.get(0).length()-1;
    do{
    String testString = grid.get(0).substring(0, size);
    int depth = 1;
    do{
    test = grid.get(0+depth).contains(testString);
    depth++;
    }while(depth < grid.size() && test == false);
    if(test == true){
    index = size;
    }
    size--;
    }while(size > 1 && test == false);
    return test;
    }
    List<String> prepareGrid(String[][] matrixGrid ){
    List<String> listGrid = new LinkedList<String>();
    for(int i = 0;i < matrixGrid.length;i++){
    String line = "";
    for(int j = 0;j < matrixGrid[0].length;j++){
    line += matrixGrid[i][j];
    }
    listGrid.add(line);
    }
    return listGrid;
    }
    List<String> printShape(String[][] matrixGrid){
    List<String> overlappedGrid = new LinkedList<String>();
    List<String> listGrid = new LinkedList<String>();
    listGrid = prepareGrid(matrixGrid);
    boolean test = calculateMaxShared(listGrid);
    if(test == true){
    for(int i = 0;i < listGrid.size();i++){
    overlappedGrid.add(listGrid.get(i));
    }
    String lastLine = "";
    for(int i = 0;i < listGrid.get(0).length()-index;i++){
    lastLine += " ";
    }
    overlappedGrid.add(lastLine);
    for(int i = 0;i < listGrid.size();i++){
    overlappedGrid.get(i+1) += listGrid.get(i).substring(index);//here is the exception
    }
    overlappedGrid.get(overlappedGrid.size()-1).concat(listGrid.get(listGrid.size()-1).substring(listGrid.get(0).length()-index));
    }
    return overlappedGrid;
    }
    }

    I tried to copy listGrid in another List<String> but the exception remain the same.

    Help me please!
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jan 2004
    Location
    Mobile, Alabama
    Posts
    4,021
    Rep Power
    1285
    Code:
    overlappedGrid.get(i+1) += listGrid.get(i).substring(index);
    Notice in this line, you are taking a value which is the result of the get method and trying to treat it like a variable. Instead of using the += operator, try using the set method
    Last edited by bullet; February 27th, 2014 at 07:55 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0
    got it, thank you!

IMN logo majestic logo threadwatch logo seochat tools logo