java uses or overrides a deprecated API error

java uses or overrides a deprecated API error

Those are not errors, they are warning, your code compiled.

To explain these lines :

Note: MyClass.java uses or overrides a deprecated API.

You are doing a call of DataInputStream#readLine which is deprecated since JDK 1.1 as per the documentation :

Deprecated.
This method does not properly convert bytes to
characters. As of JDK 1.1, the preferred way to read lines of text is
via the BufferedReader.readLine() method. Programs that use the
DataInputStream class to read lines can be converted to use the
BufferedReader class by replacing code of the form:

DataInputStream d = new DataInputStream(in);   

with:

BufferedReader d = new BufferedReader(new InputStreamReader(in));

As for the second line :

Note: Recompile with -Xlint:deprecation for details.

It simply tells you the option to use when compiling to get more details about where you are using deprecated stuff.

Edit :

As per your comment, here how your code would looks like :

import java.io.InputStreamReader;//Add these two imports
import java.io.BufferedReader;
...
BufferedReader br = new BufferedReader(new InputStreamReader(bis));//Use BufferedReader as suggested by the doc instead of DataInputStream
...
String s = br.readLine();//Read with the non-deprecated readLine of BufferedReader

From the DataInputStream API documentation:

readLine()

Deprecated.

This method does not properly convert bytes to characters. As of JDK 1.1, the preferred way to read lines of text is via the BufferedReader.readLine() method. Programs that use the DataInputStream class to read lines can be converted to use the BufferedReader class by replacing code of the form:

DataInputStream d = new DataInputStream(in);

with:
BufferedReader d
= new BufferedReader(new InputStreamReader(in));

So as you can see, in line String s = dis.readLine() in your code, you use a deprecated method. This means that there is a better option for doing what youre doing (as highlighted above). Even though the method is deprecated, it likely will work in some cases. But it isnt guaranteed to fulfill its contract anymore, and therefore it is better to use the similar but consistent BufferedReader.readLine() method.

java uses or overrides a deprecated API error

If this warning is showing up, you just uninstall your current jdk and delete its path from environment variables. And install jdk version 8(8u301) and set path again in environmental variables.

This method solved my problem

Leave a Reply

Your email address will not be published.