A.C.E的JAVA学习笔记 --## Basic Java Debugging(关于JAVA中常见的代码出错情况与解决方式)

A.C.E的学习笔记
–## Basic Java Debugging(关于JAVA中常见的代码出错情况与解决方式)
Step 1: ​“Syntax Error, Insert “;” to Complete BlockStatements”.在这里插入图片描述
This is the most basic of Syntax errors, it simply means you forgot a semicolon at the end of your statement. All declaration and expression statements will end with a semicolon. In some other instances such as with if, else, and for statements you will not need to place the semicolon.

Step 2: “cannot Be Resolved to a Variable”, or “insert VariableDeclarators”

在这里插入图片描述

This Syntax error occurs when you are attempting to use a variable without having created it first or provided it a data type. Simply add the data type that is associated with your variable, examples could be “int”, “boolean”, “char”, and “double”.

Step 3: “insert “}” to Complete ClassBody"
在这里插入图片描述

Our next Syntax error has to do with curly bracket. You will normally see the error occur when you’ve missed either one or both curly brackets. If you are missing both you will see the error, “insert “ClassBody” to complete ClassDeclaration". If only one is missing you will either see the error, “insert “}” to complete ClassBody" or “{ expected after this token”. The errors will normally occur on the line were the curly bracket can be placed to provide a fix.

Step 4: Infinite Loop
在这里插入图片描述

We now look at a case where an error will most likely not be provided by the Java client. This occurs when you have a loop such as a while loop or a for loop that cycles infinitely. There is no simple answer to the solution because each person’s code will vary but trying to add a manual supplementary limit within the code should be the primary goal. After that attempt to figure out why your code was unable to meet your loops break condition?

Step 5: “cannot Be Resolved to a Type”
在这里插入图片描述
在这里插入图片描述

This Syntax error has to do with imports. Whenever we want to use an API from another class, we must import that class to the current one. A common occurrence for this is the use of the Scanner function, in order to use it you must import the “java.util.Scanner” class. Keep in mind this is only an example.

Step 6: “The Method “” Is Undefined for the Type”
在这里插入图片描述

This Syntax error occurs when we forget the class name during a method call. The primary example for this would be whenever we attempt to print. If you’re someone who’s coming off of a language that uses a simple print() function then this can occur frequently. You will instead want to use System.out.print() or System.out.println(). This will always occur during method calls.

Step 7: “string Literal Is Not Properly Closed by a Double-quote”
在这里插入图片描述

This Syntax occurs when we are using Strings. The problem has to do with an open but not closed String. It is always marked on the line where it occurs and is fixed by placing that second double quotation. As a side note, if you attempt to use single quotations for Strings that will also result in an error “invalid character constant”.

Step 8: “return Type for the Method Is Missing”
在这里插入图片描述

在这里插入图片描述

The last Syntax worth mentioning is the method return type and missing return. The “return type for the method is missing” occurs when you have a method that attempts to return something while missing the specification of that type in the method signature. The error will occur in the signature and is usually a very fast solve. When it comes to the “method must return a result of type” error you just need to make sure you return something with that type.

Step 9: Extra Assistance
If you were unable to find a fix for your error, then consider attempting one of these following options. Copy Java’s note on the error that occurred and attempt to find a solution by pasting it into some web search. Search for some more advanced or explicit Java error handling guides. Lastly, if none of these options helped and you have the time to spare, attempt to post your question on a support forum such as Stackoverflow. You will commonly get a response fix with an explanation as to why the error occurred in the first place.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值