Results 1 to 12 of 12
  1. #1
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Search Array using Java Swing Error

    I am having an issue using netbeans with this program. The program is used to search via an array from an imported text file and the text file has several columns and rows, pertaining to several characteristics of cars (i.e. License Plate Numbers). You need to create dialog boxes to search what your looking for, for each option. The problem is at the end of the code snippet starting with one.setPlate. All of the one.set(x) is being flagged, what could be the reason?








    Java Code:
    package vehiclesearch;
    
    import java.io.File;
    import java.io.FileNotFoundException;
     import java.util.*;
    import javax.swing.JOptionPane;
    
    public class VehicleSearch {
    private static String[] sliced;
    public static void main(String[] args) throws FileNotFoundException {String NameOfFile = JOptionPane.showInputDialog("Where is the File Path to Import Located at?");
     File textFile = new File((NameOfFile));
     Scanner in = new Scanner (textFile);
    //Imports the appropriate text file named "vehicles.txt"//
     ArrayList <String> carsArrayList = new ArrayList <>();
     while(in.hasNextLine()){
       String line = in.nextLine();
         carsArrayList.add(line);
    }
          in.close();
          ArrayList<VehicleSearch> vehicleObs = new ArrayList<>();
    
                                    for (int i= 0; i <carsArrayList.size(); i++){
                                        String temp = carsArrayList.get(i);
                                        VehicleSearch one = new VehicleSearch ();
                                        String[] sliced = temp.split("\\s+");
    
                                        one.setPlate(sliced[0]);
                                        int a = Integer.parseInt(sliced[1]); 
                                        one.setYear(a);
                                        one.setMfg(sliced[2]);
                                        one.setStyle(sliced[3]);
                                        one.setColor(sliced[4]);
                                        vehicleObs.add(one);
    Last edited by derekJava; 04-17-2014 at 02:51 AM.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Search Array using Java Swing Error

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    All of the one.set(x) is being flagged
    What is the text of the error message?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    Create method "setPlate(java.lang.String)" in vehicleserach.VehicleSearch and the same goes for setYear, setMfg,setStyle,setColor.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Search Array using Java Swing Error

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    What was the meaning of post#3?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    Sorry trying to check four of my postings at once! Its now fixed.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Search Array using Java Swing Error

    Where is the full text of the error messages?

    BTW There are too many indentations. They push the code out of the viewing area.
    And it looks like the formatting has been lost. The } on line 18 should NOT be indented so far.
    Last edited by Norm; 04-17-2014 at 02:28 AM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    If you can go to this link and help me to fix the complete program from there: java - Search Array Error - Stack Overflow | You can cross-reference from there if need be.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Search Array using Java Swing Error

    Let's start with the full text of the error messages.
    If I need more, you can post it here.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    To make it easier for you, look at Namalak's version of my code, I've posted the error messages for his code already. I couldn't post images until I'm at a particular reputation there, that's why the forum post is so large.

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Search Array using Java Swing Error

    If you're having a problem getting the error messages, no problem, I can wait until you can post them here.
    I don't go to other sites for info about problems. If you want help, post the messages here.

    And text is better than images. The contents of an image can't be copied for adding to responses.
    Last edited by Norm; 04-17-2014 at 03:17 AM.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    To make it easier for you, look at Namalak's version of my code, I've posted the error messages for his code already. I couldn't post images until I'm at a particular reputation there, that's why the forum post is so large.

  12. #12
    derekJava is offline Member
    Join Date
    Apr 2014
    Posts
    9
    Rep Power
    0

    Default Re: Search Array using Java Swing Error

    Found the solution, corrupted file in the program of NetBeans, reinstalled it and violla, Netbeans is not throwing any errors. The errors was cycling to the other file (i.e. main class to the other class) vice-versa. However, I do want to thank you for your time though!
    Last edited by derekJava; 04-17-2014 at 03:38 AM.

Similar Threads

  1. Java freeze swing error?
    By MW130 in forum New To Java
    Replies: 1
    Last Post: 01-23-2013, 01:03 AM
  2. Java Array Error
    By Captain Forge in forum New To Java
    Replies: 3
    Last Post: 11-22-2012, 12:44 AM
  3. Replies: 1
    Last Post: 05-11-2012, 02:23 PM
  4. Replies: 1
    Last Post: 03-23-2012, 05:51 PM
  5. Replies: 4
    Last Post: 03-24-2011, 11:50 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
  •