Could not find the main class. Program will exit
做了好久的BS 突然有朋友讓我做一J2SE的東西 才發現Swing都被我忘光了.
做了兩天 幾個小時 才把這個簡單的東西弄出來,打包之後發現提示Could not find the main class. Program will exit 這個錯誤 這個萬惡的,令無數初學者盡折腰的錯誤.
人生也好,程式設計也好 都是在不斷的解決一個又一個問題.
當我們面臨錯誤的時候 被錯誤惡搞的時候 會感覺自己是那麼的無力啊,苦惱 煩躁 當問題解決了會有一種原來如此好似偵探破案之後的快感...
扯遠了 今天下午百度了好久才看了好多人都碰到過這種問題 解決方式也不一樣 下面羅列幾個我查到和分析之後的解決方案
1 最簡單的錯誤:MyEclipse生成 jar檔案的時候,流程是這樣, File->Export->JAR file->Next->這裡選擇你要匯出的工程並在JAR file中選擇你要匯出的位置和Jar名寫好之後 Next->我用的是MyEclipse6.5 有這頁"JAR Packaging Options" 這裡選預設繼續Next->最後一頁了 切記要指定 Mainclass 然後再 Finish一般好多新手的錯誤都處在這裡 就是沒有指定 Main class
2 這個問題比較普遍 問題產生的原因就是 電腦中可能有多個版本的Java編譯器和Jre的版本不匹配 這個問題只要讓他們匹配就好了
右鍵點選專案--->>>preference-->>>JAVA compiler 檢視編譯器版本
右鍵點選專案--->>>build path--->>>Configure build path--->>>Libraries-->>JRE system library 檢視JRE版本
就是這兩個
3 第三個錯誤和第二個差不多 又不完全一樣 第三個問題 是由於系統可能有多個JRE的版本 當執行jar檔案的時候 系統可能自作主張將我們用1.5編寫的檔案 用1.4版本去解析 這個時侯 要檢查一下 環境變數的設定和系統檔案型別(不知道該不該這麼叫)的設定
控制皮膚->資料夾選項->檔案型別->JAR下面的<高階>按紐
<操作>下面選open , 點右邊的<編輯>,修改javaw路徑,如:"C:/Program Files/Java/jdk1.5.0_10/bin/javaw.exe" -jar "%1" "%
檢查一下這個 javaw路徑是不是你想要的
4 這個是我的問題解決過程 我把它放在最後並沒有認為這個問題很高階.出問題的時候 我將上面三個都試過了還是發現 jvm依然很執著的給我 Could not find the main class. Program will exit 這個錯誤 ,後來我試著 把jar檔案用 winrar開啟 發現有些工程檔案沒有生成,其中就有我的main class類 後來 百度到一篇文章 那篇文章說的是 很多人用MyEclipse打包的時候 有寫jar包不會被打進去.
文章推薦了一個工具 叫做net.sf.fjep.fatjar 檔案 可以到http://sourceforge.net/projects/fjep或者http://download.csdn.net/source/1914933下載該“專業”打包工具,
解壓後放到eclipse的plugins下,重啟elipse,右擊待打包的專案,會看到Build Fat Jar選項 一步一步下去 就可以了 最後雙擊我的jar 發現問題解決了.
錯誤的原因 不知道是我的MyEclipse鬧脾氣了還是因為我用的是試用版本的MyEclipse
這兩天 讓我遇到和解決了很多Swing的問題 從介面設計到訊息對映 到一些細節的小問題 .這個小軟體和解決的問題比起來已經不算什麼了.
遇到南牆不要讓別人告訴你,遇到南牆只能回頭,其實可以試著推倒它.
很多失敗者往往都是失敗在終點線前的幾釐米.
執著無敵,勇往直前~!
加油~!
相關文章
- J2SE - Could not find the main class: xxx.xxx.Program will exitAI
- jar檔案could not find the main class解決JARAI
- java編譯 Error: Could not find or load main class java執行包main方法Java編譯ErrorAI
- Find User-exit and BADIs
- crontab執行jar包時,Could not find or load main class(找不到或者載入不到主類)JARAI
- swing程式打成jar包,執行出現(could not find the main class)問題,請高手指點!!JARAI
- ORA-04068,ORA-04065,ORA-06508 PL/SQL: could not find program unit being calledSQL
- Fatal error: Uncaught PDOException: could not find driverErrorException
- Could not find *.apk!解決辦法APK
- nested exception is IncompleteElementException: Could not find parameter mapException
- Could not find a suitable set of interfaces for VIPs.UI
- vue3 Could not find a declaration file for moduleVue
- 解決cannot find module providing package或cannot find main modulePackageAI
- Could not find jar tool executable問題解決JAR
- OGG-00446 ERROR: Could not find archived logErrorHive
- 錯誤 - Could not find the index entry for RIDIndex
- ogg GGS ERROR 500 Could not find archived logErrorHive
- SQL error 2812: Could not find stored procedure.docSQLError
- cmake報錯CMake Error: Could not find CMAKE_ROOTError
- 關於 artisan migrants Could not find drive 解決方法
- Helper Devise: could not find the `Warden::Proxy` instance on request environmentdev
- master bug InnoDB Error unlock row could not find a 4 mode lockASTError
- Could not find first log file name in binary log index fileIndex
- FATAL ERROR: Could not find ./bin/my_print_defaults 解決方法Error
- 請教:castor MappingException: Could not find the class異常ASTAPPException
- 解決CocoaPods could not find compatible versions for pod "React/Core"React
- PostgreSQL pg_rewind例項--could not find previous WAL record at %X/%XSQL
- This application failed to start because it could not find or load the Qt platform plugin “windows“APPAIQTPlatformPluginWindows
- java.lang.IllegalArgumentException: Could not find class異常解決方式JavaException
- Application failed to start because it could not find or load the QT platform plugin “windows”APPAIQTPlatformPluginWindows
- Error:Could not find com.android.tools.build:gradle:2.2.2.ErrorAndroidUIGradle
- mount iso檔案的時候提示Could not find any loop deviceOOPdev
- iOS-拉outlet到程式碼區錯誤:Could not insert new outlet connection: Could not find any...iOS
- Could not find or access '/etc/ansible/bin/cfssljson /etc/ansible/bin/cfsslJSON
- 引入第三方庫報錯Could not find method apt() for argumentsAPT
- nancy Unable to find view engine that could render the view 無法找到檢視模板引擎NaNView
- ERROR | [iOS] unknown: Encountered an unknown error (Could not find a `ios` simulator (valid values:ErroriOS
- Could not find a version that satisfies the requirement py4j (from versions: ) No matching distributUIREM