A simple process of "class name is accepted only when explicit request annotation is processed" is run using Java commands.

Source: Internet
Author: User

When you use Java commands for the first time to run a Java program, the system sometimes throws the error message "class name is accepted only when explicit request annotation is processed". why and how can this problem be solved.

See the following code:

Import javax. swing. jframe; <br/> Import javax. swing. jbutton; <br/> public class myframe extends javax. swing. jframe {<br/> jbutton = NULL; <br/> Public myframe () {<br/> initbutton (); <br/> Add (button ); <br/> This. setsize (400,400); <br/> This. show (); <br/>}</P> <p> private void initbutton () {<br/> If (Button = NULL) {<br/> button = new jbutton ("OK"); <br/>}< br/> Public static void main (string [] ARGs) {<br/> New myframe (); <br/>}< br/>

This code is actually very easy to put a jbutton in a jframe.

Use javac to compile and generate class

When running in Java, "class names are accepted only when explicit request annotation is processed" is reported ".

In fact, the reason is very simple, because the show method is an outdated method. Solution:

The following prompt is displayed when you use javac to compile the class:

Note: myframe. Java uses or overwrites outdated APIs.

Note: For details, use-xlint: deprecation to re-compile.

Next, we only need to recompile the code using this method:

Javac-xlint: deprecation myframe. Java

The list of expired methods will be listed after execution, which can be ignored as long as the class file is correctly compiled

The above error message is not displayed when you run the class file using the Java command.

 

The solution is very simple. Many people have asked such questions on the Internet, but there are very few answers to the questions. Therefore, we will analyze the problems and then think about them.

End

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.