Results 1 to 3 of 3
  1. #1
    765891 is offline Member
    Join Date
    Jan 2013
    Location
    'Murica
    Posts
    25
    Rep Power
    0

    Unhappy File reading values to draw an image (java graphics drawString/ arrayList/Array)

    //compiler error I'm receiving
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:41: error: cannot find symbol
    xcor.add(read.nexInt());
    ^
    symbol: method nexInt()
    location: variable read of type Scanner
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:42: error: cannot find symbol
    ycor.add(read.nexInt());
    ^
    symbol: method nexInt()
    location: variable read of type Scanner
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:43: error: cannot find symbol
    colour.add(read.nexInt());
    ^
    symbol: method nexInt()
    location: variable read of type Scanner
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:46: error: incompatible types
    int[] xcorA = new Integer[xcor.size()];
    ^
    required: int[]
    found: Integer[]
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:47: error: incompatible types
    int[] ycorA = new Integer[ycor.size()];
    ^
    required: int[]
    found: Integer[]
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:48: error: incompatible types
    int[] colourA = new Integer[colour.size()];
    ^
    required: int[]
    found: Integer[]
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:49: error: no suitable method found for toArray(int[])
    xcorA = xcor.toArray(xcorA);
    ^
    method ArrayList.<T>toArray(T[]) is not applicable
    (inferred type does not conform to declared bound(s)
    inferred: int
    bound(s): Object)
    method ArrayList.toArray() is not applicable
    (actual and formal argument lists differ in length)
    where T is a type-variable:
    T extends Object declared in method <T>toArray(T[])
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:50: error: no suitable method found for toArray(int[])
    ycorA = ycor.toArray(ycorA);
    ^
    method ArrayList.<T>toArray(T[]) is not applicable
    (inferred type does not conform to declared bound(s)
    inferred: int
    bound(s): Object)
    method ArrayList.toArray() is not applicable
    (actual and formal argument lists differ in length)
    where T is a type-variable:
    T extends Object declared in method <T>toArray(T[])
    J:\CS3\Student Folder Review Lab #2\APlusImage.java:51: error: no suitable method found for toArray(int[])
    colourA = colour.toArray(colourA);
    ^
    method ArrayList.<T>toArray(T[]) is not applicable
    (inferred type does not conform to declared bound(s)
    inferred: int
    bound(s): Object)
    method ArrayList.toArray() is not applicable
    (actual and formal argument lists differ in length)
    where T is a type-variable:
    T extends Object declared in method <T>toArray(T[])
    9 errors


    Process completed.
    //run time error I'm receiving
    Error: Main method not found in class APlusImage, please define the main method as: public static void main(String[] args)


    Java Code:
    //data file information
    640 480
    90 150 2
    100 140 4
    110 130 6
    120 120 8
    90 160 2
    100 170 4
    110 180 6
    120 190 8
    130 190 2
    140 180 4
    150 170 6
    160 160 8
    130 120 2
    140 130 4
    150 140 6
    160 150 8
    170 150 10
    180 150 10
    190 150 10
    170 160 10
    180 160 10
    190 160 10
    120 150 10
    130 150 10
    120 160 10
    130 160 10



    Java Code:
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.*;
    import java.util.*;
    import java.awt.Canvas;
    import java.io.*;
    
    
    public class APlusImage extends Canvas
    {
    	private int[][] image;
    	private String fileName;
    	
    	public static void main(String[] args) 
    	{
    		
    	}
    	
    	public APlusImage()
    	{
    		
    		File file = new File("image.dat");
    		ArrayList<Integer> xcor=new ArrayList<Integer>();
    		ArrayList<Integer> ycor=new ArrayList<Integer>();
    		ArrayList<Integer> colour=new ArrayList<Integer>();
    		int width;
    		int height;
    		try{
    		   //read from the file
    		    Scanner read = new Scanner(file);
    			//load the file information
    			  width=read.nextInt();
    			  height=read.nextInt();
    			while (read.hasNextLine())
    			{                
    			    xcor.add(read.nexInt());
    			    ycor.add(read.nexInt());
    			    colour.add(read.nexInt());
    			 }
    			//into the matrix
    			int[] xcorA = new Integer[xcor.size()];
    			int[] ycorA = new Integer[ycor.size()];
    			int[] colourA = new Integer[colour.size()];
        		xcorA = xcor.toArray(xcorA);
        		ycorA = ycor.toArray(ycorA);
        		colourA = colour.toArray(colourA);
    
    
    
    
    		}
    		catch(Exception e)
    		{
    			
    		}
    		
    		setSize( width, height );
    		setBackground(Color.WHITE);
    		setVisible(true);
    	}
    
    
    	public APlusImage(String name)
    	{
    		try{
    		   //read from the file
    			//load the file information
    			//into the matrix
    
    
    		}
    		catch(Exception e)
    		{
    			
    		}
    		
    		setSize( 640, 480 );
    		setBackground(Color.WHITE);
    		setVisible(true);
    	}
    
    
    	public void paint( Graphics window )
    	{
    		window.setFont(new Font("TAHOMA",Font.BOLD,12));
    		window.setColor(Color.BLUE);
    		window.drawString("Lab16g",420,40);
    		window.drawString("IMAGES", 420,55);
    		
    		showImage(window);		
    	}
    	
    	public void showImage(Graphics window)
    	{
    		//roygbiv
    		//2 red
    		//4 orange
    		//6 yellow
    		//8 green
    		//10 blue
    		//12 indigo
    		//14 violet
    		
    		//draw the image on the screen
    	}
    
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: File reading values to draw an image (java graphics drawString/ arrayList/Array)

    The method name is 'nextInt()', not 'nexInt()'.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    393
    Rep Power
    9

    Default Re: File reading values to draw an image (java graphics drawString/ arrayList/Array)

    There is also confusion between the primitive int and the object Integer. Unless you specifically require an Integer then stick to ints.
    It is also pointless trying to run the application if there are compilation failures.

    Regards.

Similar Threads

  1. array or arraylist for reading file
    By denpetro in forum New To Java
    Replies: 11
    Last Post: 11-14-2012, 01:59 PM
  2. Replies: 2
    Last Post: 02-07-2012, 03:32 PM
  3. Help : reading image and draw it on GUI
    By Rodrigo91 in forum Java 2D
    Replies: 0
    Last Post: 03-26-2011, 10:01 PM
  4. Replies: 14
    Last Post: 01-22-2011, 02:36 PM
  5. Method Graphics.drawString() - Symbol not found
    By km0r3 in forum AWT / Swing
    Replies: 1
    Last Post: 08-27-2010, 02:55 PM

Tags for this Thread

Posting Permissions

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