Results 1 to 2 of 2
  1. #1
    allayahassine is offline Member
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default 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.j ava: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
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,378
    Rep Power
    5

    Default Re: Data Structure Construction

    First, place you code between [code] [/code] tags for proper formatting.
    Then sprinkle some meaningful comments thru out your code to document it.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Query about data structure
    By chkontog in forum New To Java
    Replies: 0
    Last Post: 11-25-2012, 10:01 AM
  2. Which data structure to use?
    By malaguena in forum New To Java
    Replies: 4
    Last Post: 04-05-2011, 04:41 PM
  3. data structure and data base??
    By ahmed13 in forum Advanced Java
    Replies: 8
    Last Post: 03-27-2009, 05:48 AM
  4. data file structure
    By Nicholas Jordan in forum Advanced Java
    Replies: 2
    Last Post: 01-07-2009, 04:16 AM
  5. Queue data structure
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •