Java Error(一)
生活随笔
收集整理的這篇文章主要介紹了
Java Error(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、Resource? leak: 'xxx' is never closed
原因:打開了reader 、Scanner等,未關閉,導致內存泄漏。解決方案:
public void readShapeData() throws IOException {Scanner in = new Scanner(System.in);try {System.out.println("Enter the width of the Rectangle: ");width = in.nextDouble();System.out.println("Enter the height of the Rectangle: ");height = in.nextDouble();} finally {in.close();} }?
使用try{}? finally{} block來解決。try{}中可能會拋出異常的part,用于測試。finally{}中為不管怎樣,最終都要執行的步驟。類似Python,或者是Python的開發人員保留了Java這一特征。
避免了因Logic Flaw 導致一直調用內存資源,導致內存資源不足。
?
2、jdk 安裝環境,cmd中輸入javac? ?類名.java 顯示錯誤
錯誤: 找不到或無法加載主類 HelloWrold? 原因: java.lang.ClassNotFoundException: HelloWorld(找不到HelloWorld 該類 )
1、沒有定義public class 類,如class HelloWorld{ ....}
2、public class 類名與文件名書寫有出入,大小寫、符號等等。
轉載于:https://www.cnblogs.com/leafh/p/8581750.html
總結
以上是生活随笔為你收集整理的Java Error(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于CoordinatorLayout的
- 下一篇: 20180316 数组所占空间