Why am I getting an error calling this readFile method? [duplicate]












0
















This question already has an answer here:




  • What causes javac to issue the “uses unchecked or unsafe operations” warning

    8 answers




I'm getting an error using the method readFile which I used in the class RunProgram.



The error I'm getting is:




RunProgram.java uses unchecked or unsafe operations.




The code of my RunProgram class is:



 import java.util.ArrayList;

public class RunProgram{
public static void main(String args){

String namen = Input.geefInputNamen();

ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
spelerDatabase = FileReader.readFile("Player Database");
}
}


The method readFile is defined in the code below:



 import java.io.*;
import java.util.ArrayList;

public class FileReader {

public static ArrayList readFile(String naamvdfile) {
ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
try {
int LineNr = 4;
File aFile = new File (naamvdfile+ ".xlsx");
BufferedReader aBr = new BufferedReader(new java.io.FileReader(aFile));
String aLine ="";
while (aLine !=> null) {
aLine = aBr.readLine();
if (aLine != null) {
String lineParts = aLine.split(";", -1);
if (lineParts.length == 10) {

int overall = Integer.parseInt(lineParts[1]);
int shootMid = Integer.parseInt(lineParts[4]);
int shootDis = Integer.parseInt(lineParts[5]);
int defence = Integer.parseInt(lineParts[6]);
int rebounden = Integer.parseInt(lineParts[7]);
int playmaker = Integer.parseInt(lineParts[8]);
int atletisch = Integer.parseInt(lineParts[9]);

Spelers speler = new Spelers(lineParts[0], overall,
lineParts[2], lineParts[3], shootMid, shootDis,
defence, rebounden, playmaker, atletisch);
spelerDatabase.add(speler);
}
else System.out.println("Lijn " + LineNr +" is niet volledig
ingevuld!");
LineNr++;
}
}
System.out.println("Aantal spelers dat we inlazen: " + LineNr);
}
catch (Exception e) { }
return spelerDatabase;
}
}


This last code doesn't give an error while compiling.










share|improve this question















marked as duplicate by DaveyDaveDave, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 14:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • what is the issue then?

    – Ankur Chrungoo
    Nov 21 '18 at 14:28






  • 1





    I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

    – TheJavaGuy-Ivan Milosavljević
    Nov 21 '18 at 14:30











  • yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

    – Pieter De Smet
    Nov 21 '18 at 14:33











  • I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

    – Joakim Danielson
    Nov 21 '18 at 14:34











  • Related: What is a raw type and why shouldn't we use it?

    – LuCio
    Nov 21 '18 at 14:38
















0
















This question already has an answer here:




  • What causes javac to issue the “uses unchecked or unsafe operations” warning

    8 answers




I'm getting an error using the method readFile which I used in the class RunProgram.



The error I'm getting is:




RunProgram.java uses unchecked or unsafe operations.




The code of my RunProgram class is:



 import java.util.ArrayList;

public class RunProgram{
public static void main(String args){

String namen = Input.geefInputNamen();

ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
spelerDatabase = FileReader.readFile("Player Database");
}
}


The method readFile is defined in the code below:



 import java.io.*;
import java.util.ArrayList;

public class FileReader {

public static ArrayList readFile(String naamvdfile) {
ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
try {
int LineNr = 4;
File aFile = new File (naamvdfile+ ".xlsx");
BufferedReader aBr = new BufferedReader(new java.io.FileReader(aFile));
String aLine ="";
while (aLine !=> null) {
aLine = aBr.readLine();
if (aLine != null) {
String lineParts = aLine.split(";", -1);
if (lineParts.length == 10) {

int overall = Integer.parseInt(lineParts[1]);
int shootMid = Integer.parseInt(lineParts[4]);
int shootDis = Integer.parseInt(lineParts[5]);
int defence = Integer.parseInt(lineParts[6]);
int rebounden = Integer.parseInt(lineParts[7]);
int playmaker = Integer.parseInt(lineParts[8]);
int atletisch = Integer.parseInt(lineParts[9]);

Spelers speler = new Spelers(lineParts[0], overall,
lineParts[2], lineParts[3], shootMid, shootDis,
defence, rebounden, playmaker, atletisch);
spelerDatabase.add(speler);
}
else System.out.println("Lijn " + LineNr +" is niet volledig
ingevuld!");
LineNr++;
}
}
System.out.println("Aantal spelers dat we inlazen: " + LineNr);
}
catch (Exception e) { }
return spelerDatabase;
}
}


This last code doesn't give an error while compiling.










share|improve this question















marked as duplicate by DaveyDaveDave, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 14:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















  • what is the issue then?

    – Ankur Chrungoo
    Nov 21 '18 at 14:28






  • 1





    I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

    – TheJavaGuy-Ivan Milosavljević
    Nov 21 '18 at 14:30











  • yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

    – Pieter De Smet
    Nov 21 '18 at 14:33











  • I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

    – Joakim Danielson
    Nov 21 '18 at 14:34











  • Related: What is a raw type and why shouldn't we use it?

    – LuCio
    Nov 21 '18 at 14:38














0












0








0









This question already has an answer here:




  • What causes javac to issue the “uses unchecked or unsafe operations” warning

    8 answers




I'm getting an error using the method readFile which I used in the class RunProgram.



The error I'm getting is:




RunProgram.java uses unchecked or unsafe operations.




The code of my RunProgram class is:



 import java.util.ArrayList;

public class RunProgram{
public static void main(String args){

String namen = Input.geefInputNamen();

ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
spelerDatabase = FileReader.readFile("Player Database");
}
}


The method readFile is defined in the code below:



 import java.io.*;
import java.util.ArrayList;

public class FileReader {

public static ArrayList readFile(String naamvdfile) {
ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
try {
int LineNr = 4;
File aFile = new File (naamvdfile+ ".xlsx");
BufferedReader aBr = new BufferedReader(new java.io.FileReader(aFile));
String aLine ="";
while (aLine !=> null) {
aLine = aBr.readLine();
if (aLine != null) {
String lineParts = aLine.split(";", -1);
if (lineParts.length == 10) {

int overall = Integer.parseInt(lineParts[1]);
int shootMid = Integer.parseInt(lineParts[4]);
int shootDis = Integer.parseInt(lineParts[5]);
int defence = Integer.parseInt(lineParts[6]);
int rebounden = Integer.parseInt(lineParts[7]);
int playmaker = Integer.parseInt(lineParts[8]);
int atletisch = Integer.parseInt(lineParts[9]);

Spelers speler = new Spelers(lineParts[0], overall,
lineParts[2], lineParts[3], shootMid, shootDis,
defence, rebounden, playmaker, atletisch);
spelerDatabase.add(speler);
}
else System.out.println("Lijn " + LineNr +" is niet volledig
ingevuld!");
LineNr++;
}
}
System.out.println("Aantal spelers dat we inlazen: " + LineNr);
}
catch (Exception e) { }
return spelerDatabase;
}
}


This last code doesn't give an error while compiling.










share|improve this question

















This question already has an answer here:




  • What causes javac to issue the “uses unchecked or unsafe operations” warning

    8 answers




I'm getting an error using the method readFile which I used in the class RunProgram.



The error I'm getting is:




RunProgram.java uses unchecked or unsafe operations.




The code of my RunProgram class is:



 import java.util.ArrayList;

public class RunProgram{
public static void main(String args){

String namen = Input.geefInputNamen();

ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
spelerDatabase = FileReader.readFile("Player Database");
}
}


The method readFile is defined in the code below:



 import java.io.*;
import java.util.ArrayList;

public class FileReader {

public static ArrayList readFile(String naamvdfile) {
ArrayList<Spelers> spelerDatabase = new ArrayList<Spelers>();
try {
int LineNr = 4;
File aFile = new File (naamvdfile+ ".xlsx");
BufferedReader aBr = new BufferedReader(new java.io.FileReader(aFile));
String aLine ="";
while (aLine !=> null) {
aLine = aBr.readLine();
if (aLine != null) {
String lineParts = aLine.split(";", -1);
if (lineParts.length == 10) {

int overall = Integer.parseInt(lineParts[1]);
int shootMid = Integer.parseInt(lineParts[4]);
int shootDis = Integer.parseInt(lineParts[5]);
int defence = Integer.parseInt(lineParts[6]);
int rebounden = Integer.parseInt(lineParts[7]);
int playmaker = Integer.parseInt(lineParts[8]);
int atletisch = Integer.parseInt(lineParts[9]);

Spelers speler = new Spelers(lineParts[0], overall,
lineParts[2], lineParts[3], shootMid, shootDis,
defence, rebounden, playmaker, atletisch);
spelerDatabase.add(speler);
}
else System.out.println("Lijn " + LineNr +" is niet volledig
ingevuld!");
LineNr++;
}
}
System.out.println("Aantal spelers dat we inlazen: " + LineNr);
}
catch (Exception e) { }
return spelerDatabase;
}
}


This last code doesn't give an error while compiling.





This question already has an answer here:




  • What causes javac to issue the “uses unchecked or unsafe operations” warning

    8 answers








java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 14:57









Mark Rotteveel

59.7k1476119




59.7k1476119










asked Nov 21 '18 at 14:26









Pieter De SmetPieter De Smet

72




72




marked as duplicate by DaveyDaveDave, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 14:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by DaveyDaveDave, Mark Rotteveel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 14:58


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • what is the issue then?

    – Ankur Chrungoo
    Nov 21 '18 at 14:28






  • 1





    I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

    – TheJavaGuy-Ivan Milosavljević
    Nov 21 '18 at 14:30











  • yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

    – Pieter De Smet
    Nov 21 '18 at 14:33











  • I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

    – Joakim Danielson
    Nov 21 '18 at 14:34











  • Related: What is a raw type and why shouldn't we use it?

    – LuCio
    Nov 21 '18 at 14:38



















  • what is the issue then?

    – Ankur Chrungoo
    Nov 21 '18 at 14:28






  • 1





    I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

    – TheJavaGuy-Ivan Milosavljević
    Nov 21 '18 at 14:30











  • yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

    – Pieter De Smet
    Nov 21 '18 at 14:33











  • I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

    – Joakim Danielson
    Nov 21 '18 at 14:34











  • Related: What is a raw type and why shouldn't we use it?

    – LuCio
    Nov 21 '18 at 14:38

















what is the issue then?

– Ankur Chrungoo
Nov 21 '18 at 14:28





what is the issue then?

– Ankur Chrungoo
Nov 21 '18 at 14:28




1




1





I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

– TheJavaGuy-Ivan Milosavljević
Nov 21 '18 at 14:30





I'm pretty sure this is invalid Java: while (aLine !=> null). You probably wanted to write while (aLine != null)

– TheJavaGuy-Ivan Milosavljević
Nov 21 '18 at 14:30













yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

– Pieter De Smet
Nov 21 '18 at 14:33





yeah you are right, but in my code it is correct, while uploading it to the forum I accidently added an > to it :)

– Pieter De Smet
Nov 21 '18 at 14:33













I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

– Joakim Danielson
Nov 21 '18 at 14:34





I also think you will have an issue with the filename parameter when it contains a space, maybe calling it with quotes is better ""Player Database""

– Joakim Danielson
Nov 21 '18 at 14:34













Related: What is a raw type and why shouldn't we use it?

– LuCio
Nov 21 '18 at 14:38





Related: What is a raw type and why shouldn't we use it?

– LuCio
Nov 21 '18 at 14:38












2 Answers
2






active

oldest

votes


















0














Change the function return type to ArrayList<Spelers> in the below function in FileReader class :



  public static ArrayList<Spelers> readFile(String naamvdfile) {
...


The RunProgram class is expecting an ArrayList<Spelers> whereas the method signature tells it that the return type is an untyped ArrayList.






share|improve this answer































    0














    You get an unchecked warning because readFile() returns an ArrayList while you save it to an object of type ArrayList<Spelers>. Simply change the return type of the method.



    public static ArrayList<Spelers> readFile(String naamvdfile) {
    ....
    }





    share|improve this answer


























    • i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

      – Pieter De Smet
      Nov 21 '18 at 14:34








    • 1





      Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

      – Rogue
      Nov 21 '18 at 14:36


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Change the function return type to ArrayList<Spelers> in the below function in FileReader class :



      public static ArrayList<Spelers> readFile(String naamvdfile) {
    ...


    The RunProgram class is expecting an ArrayList<Spelers> whereas the method signature tells it that the return type is an untyped ArrayList.






    share|improve this answer




























      0














      Change the function return type to ArrayList<Spelers> in the below function in FileReader class :



        public static ArrayList<Spelers> readFile(String naamvdfile) {
      ...


      The RunProgram class is expecting an ArrayList<Spelers> whereas the method signature tells it that the return type is an untyped ArrayList.






      share|improve this answer


























        0












        0








        0







        Change the function return type to ArrayList<Spelers> in the below function in FileReader class :



          public static ArrayList<Spelers> readFile(String naamvdfile) {
        ...


        The RunProgram class is expecting an ArrayList<Spelers> whereas the method signature tells it that the return type is an untyped ArrayList.






        share|improve this answer













        Change the function return type to ArrayList<Spelers> in the below function in FileReader class :



          public static ArrayList<Spelers> readFile(String naamvdfile) {
        ...


        The RunProgram class is expecting an ArrayList<Spelers> whereas the method signature tells it that the return type is an untyped ArrayList.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 14:32









        PranjalPranjal

        1363




        1363

























            0














            You get an unchecked warning because readFile() returns an ArrayList while you save it to an object of type ArrayList<Spelers>. Simply change the return type of the method.



            public static ArrayList<Spelers> readFile(String naamvdfile) {
            ....
            }





            share|improve this answer


























            • i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

              – Pieter De Smet
              Nov 21 '18 at 14:34








            • 1





              Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

              – Rogue
              Nov 21 '18 at 14:36
















            0














            You get an unchecked warning because readFile() returns an ArrayList while you save it to an object of type ArrayList<Spelers>. Simply change the return type of the method.



            public static ArrayList<Spelers> readFile(String naamvdfile) {
            ....
            }





            share|improve this answer


























            • i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

              – Pieter De Smet
              Nov 21 '18 at 14:34








            • 1





              Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

              – Rogue
              Nov 21 '18 at 14:36














            0












            0








            0







            You get an unchecked warning because readFile() returns an ArrayList while you save it to an object of type ArrayList<Spelers>. Simply change the return type of the method.



            public static ArrayList<Spelers> readFile(String naamvdfile) {
            ....
            }





            share|improve this answer















            You get an unchecked warning because readFile() returns an ArrayList while you save it to an object of type ArrayList<Spelers>. Simply change the return type of the method.



            public static ArrayList<Spelers> readFile(String naamvdfile) {
            ....
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 21 '18 at 14:35

























            answered Nov 21 '18 at 14:30









            TuramarthTuramarth

            1,19541619




            1,19541619













            • i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

              – Pieter De Smet
              Nov 21 '18 at 14:34








            • 1





              Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

              – Rogue
              Nov 21 '18 at 14:36



















            • i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

              – Pieter De Smet
              Nov 21 '18 at 14:34








            • 1





              Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

              – Rogue
              Nov 21 '18 at 14:36

















            i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

            – Pieter De Smet
            Nov 21 '18 at 14:34







            i don't get it, do i need to change my return type to ArrayList<Spelers>? Anyway, the things works now :)

            – Pieter De Smet
            Nov 21 '18 at 14:34






            1




            1





            Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

            – Rogue
            Nov 21 '18 at 14:36





            Correct. The name for what you were using was a "raw type". By omitting the generic type witness you also removed (albeit temporarily) a lot of the type safety surrounding the List.

            – Rogue
            Nov 21 '18 at 14:36



            Popular posts from this blog

            Ottavio Pratesi

            Tricia Helfer

            15 giugno