Using Editor Hints to Fix Code
See Also
As you are typing in the Source Editor, the IDE detects and marks errors with
the error glyph (
) and
other markers. For some errors, the IDE can suggest can suggest a solution
and generate the necessary code. When the IDE can provide such a hint to
correct the error, the lightbulb icon
(
) appears in the
left margin.
To display hints and generate a correction for your code:
- When the lightbulb icon
(
) appears,
press Alt-Enter to display the hint.
- Select a suggestion from the drop-down list and press Enter.
- Editor hints only appear when the insertion point is on
the line where the error is detected and the hint is available. You can
jump to an error line by clicking the error marker
(
) in the right
margin. If a hint is available for that error, the lightbulb icon
(
) appears once
you have jumped to that line.
Editor hints are available to do the following things:
- Insert a missing import statement.
- Insert abstract methods for classes you are extending or interfaces
that you are implementing.
- Create a parameter. For example, this hint appears if you have
typed a variable in a return statement that has not yet been
created.
- Create a field. For example, this hint appears if you have
typed a variable in a return statement that has not yet been
created.
- Create a local variable. For example, this hint appears if you have
typed a variable in a return statement that has not yet been
created.
- Create a method. For example, this hint occurs if you assign a method
that you have not yet created.
- Initialize a variable. For example, this hint appears if you have
declared a variable and then referenced that variable without having
first given it a value.
- Insert a cast statement when incompatible types arise in code. For example,
an incompatible types error can occur when you assign an element from a list
to a variable and the variable is of a narrower type than the element being
assigned to it.
- Surround a block with try and catch statements.
- Generate a throws clause for an exception.
- Make the current class abstract. This hint is available if you have abstract
methods in your class and have not added the abstract keyword in
your class declaration. You need to jump to the class declaration in order to access
this hint.
- See Also
- Identifying Errors in Source Code
- Completing a Java Expression
- Inserting Code From a Template
- Using the Word Match Feature
Legal Notices