eclipse解決editor does not contain a main type的方法

來源:互聯網
上載者:User

標籤:blog   http   os   ar   檔案   sp   art   問題   on   

轉自:http://blog.csdn.net/huazhangena/article/details/7349044

寫在前面的話:我的也出現這個問題,但是解決方案和轉寄的內容不太一樣,原理一樣,我是右擊src--build path--use as source folder,估計以前是刪除了工程中的部分東西,如果針對其他檔案夾報錯的會出現很多,不要擔心,再remove source folder就行了,記得運行之後重啟,還有包估計要重新rebuild source一下。

 

今天用eclipse,當打算run一個帶有main函數的class時,出現editor does not contain a main type的錯誤框。

baidu了一下,迅速解決問題:原來這個class所在包沒有被添加到build path中。

解決方案:在左側的package explorer中右擊這個class所在包的上一級目錄--build path--use as source folder。這樣就解決問題了。

重新開啟class,再run一下,ok了。

 

-----------------------------------------------------
補充和解釋:

哎,好吧。再稍微簡單解釋下。


看這張圖,src就是在build path中的(仔細觀察src的表徵圖) 
相對的,resource就只是個普通檔案夾,而不在build path中(表徵圖和src不一樣吧?) 
然後我又在resource下建立了檔案夾和檔案,比較下,包和檔案夾的表徵圖也是不一樣的。

現在,我要把resource也加到build path中。(方法就是右擊resource--build path--use as source folder)

這樣,src和resource就都在build path中了。

最後,解釋下,什麼叫“在build path中”?你可以這麼理解,eclipse中,在build path下的類可以被編譯運行,在build path下的設定檔可以被類以相對路徑直接讀寫。

eclipse解決editor does not contain a main type的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.