本文目錄一覽:
- 1、java.lang.IndexOutOfBoundsException:
- 2、java.lang.OutOfMemoryError: Java heap space
- 3、我用myeclipse寫java代碼出了一個異常。我點了一下thread.java。然後就出現了一
- 4、java報錯beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based!
- 5、為什麼 beyond compare 不能打開java的class文件,提示轉換錯誤
java.lang.IndexOutOfBoundsException:
該異常通常是指數組下標越界異常。
例如:一個ArrayList數組中沒有元素,而你想獲取第一個元素,運行是就會報此類型的錯誤。
案例如下:
擴展資料:
java中還有其他幾種常見異常
1、java.lang.NullPointerException
該異常的解釋是”程序遇上了空指針”,簡單地說就是調用了未經初始化的對象或者是不存在的對象,這個錯誤經常出現在創建圖片,調用數組這些操作中,比如圖片未經初始化,或者圖片創建時的路徑錯誤等等。
2、java.lang.ClassNotFoundException
該異常的解釋是“指定的類不存在”,這裡主要考慮一下類的名稱和路徑是否正確即可,如果是在eclipse等開發工具下做的程序包,一般都是默認加上Package的,所以轉到WTK下後要注意把Package的路徑加上。
3、java.lang.ArithmeticException
該異常的解釋是“數學運算異常”,比如程序中出現了除以零這樣的運算就會出這樣的異常,對這種異常,要檢查一下自己程序中涉及到數學運算的地方,公式是不是有不妥。
4、java.lang.ArrayIndexOutOfBoundsException
該異常的解釋是“數組下標越界”,現在程序中大多都有對數組的操作,因此在調用數組的時候一定要認真檢查,看自己調用的下標是不是超出了數組的範圍。
5、java.lang.IllegalArgumentException
該異常的解釋是“方法的參數錯誤”,很多J2ME的類庫中的方法在一些情況下都會引發這樣的錯誤,比如音量調節方法中的音量參數如果寫成負數就會出現這個異常。
6、java.sql.SQLException
該異常的解釋是“Sql語句執行異常”,由數據庫管理系統拋出至服務器,應檢查sql語句是否書寫正確等。
參考資料:jdk9官方文檔-Exception類
java.lang.OutOfMemoryError: Java heap space
Java的堆內存溢出了,可能是由於你的某個方法BUG導致的,比如構造了一個List,一次放入的數據過多,或者一次讀取某個很大的文件,而沒有使用緩存
根本的解決方法是查找導致溢出的方法,並修正(可以減少放入內存的內容)
另外有一個治標的方法:在WEB容器啟動時加上內存參數:
-Xms512m -Xmx512m
如果改JVM不行,那就查看下是否程序上有問題。
---------------此問題答案引用於:beyondts
我用myeclipse寫java代碼出了一個異常。我點了一下thread.java。然後就出現了一
package java.lang;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.AccessControlContext;
import java.security.PrivilegedAction;
import java.util.Map;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.LockSupport;
import sun.nio.ch.Interruptible;
import sun.reflect.CallerSensitive;
import sun.reflect.Reflection;
import sun.security.util.SecurityConstants;
/**
* A ithread/i is a thread of execution in a program. The Java
* Virtual Machine allows an application to have multiple threads of
* execution running concurrently.
* p
* Every thread has a priority. Threads with higher priority are
* executed in preference to threads with lower priority. Each thread
* may or may not also be marked as a daemon. When code running in
* some thread creates a new codeThread/code object, the new
* thread has its priority initially set equal to the priority of the
* creating thread, and is a daemon thread if and only if the
* creating thread is a daemon.
* p
* When a Java Virtual Machine starts up, there is usually a single
* non-daemon thread (which typically calls the method named
* codemain/code of some designated class). The Java Virtual
* Machine continues to execute threads until either of the following
* occurs:
* ul
* liThe codeexit/code method of class codeRuntime/code has been
* called and the security manager has permitted the exit operation
* to take place.
* liAll threads that are not daemon threads have died, either by
* returning from the call to the coderun/code method or by
* throwing an exception that propagates beyond the coderun/code
* method.
* /ul
* p
* There are two ways to create a new thread of execution. One is to
* declare a class to be a subclass of codeThread/code. This
* subclass should override the coderun/code method of class
* codeThread/code. An instance of the subclass can then be
* allocated and started. For example, a thread that computes primes
* larger than a stated value could be written as follows:
* phrblockquotepre
* class PrimeThread extends Thread {
* long minPrime;
* PrimeThread(long minPrime) {
* this.minPrime = minPrime;
* }
*
* public void run() {
* // compute primes larger than minPrime
* . . .
* }
* }
* /pre/blockquotehr
* p
* The following code would then create a thread and start it running:
* pblockquotepre
* PrimeThread p = new PrimeThread(143);
* p.start();
* /pre/blockquote
* p
* The other way to create a thread is to declare a class that
* implements the codeRunnable/code interface. That class then
* implements the coderun/code method. An instance of the class can
* then be allocated, passed as an argument when creating
* codeThread/code, and started. The same example in this other
* style looks like the following:
* phrblockquotepre
* class PrimeRun implements Runnable {
* long minPrime;
* PrimeRun(long minPrime) {
* this.minPrime = minPrime;
* }
*
* public void run() {
* // compute primes larger than minPrime
* . . .
* }
* }
* /pre/blockquotehr
* p
* The following code would then create a thread and start it running:
* pblockquotepre
* PrimeRun p = new PrimeRun(143);
* new Thread(p).start();
* /pre/blockquote
* p
* Every thread has a name for identification purposes. More than
* one thread may have the same name. If a name is not specified when
* a thread is created, a new name is generated for it.
* p
* Unless otherwise noted, passing a {@code null} argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.
*
* @author unascribed
* @see Runnable
* @see Runtime#exit(int)
* @see #run()
* @see #stop()
* @since JDK1.0
*/
public
class Thread implements Runnable {
中間省略…
/* Some private helper methods */
private native void setPriority0(int newPriority);
private native void stop0(Object o);
private native void suspend0();
private native void resume0();
private native void interrupt0();
private native void setNativeName(String name);
}
對比下 這個就是 線程 Thread 類 2058行
java報錯beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based!
hql多了參數了,你就一個佔位符 – 即?,卻使用了query.setParameter(2, “%” + filter.getKeyWord() + “%”);
為什麼 beyond compare 不能打開java的class文件,提示轉換錯誤
用 Beyond Compare 3 的 Data Compare 可以達到目的: 在 Data Compare 兩側載入文件(或剪貼板內容),Data Compare 會自動識別分隔符並分列。 下面進行“對齊B列”的操作: 打開菜單:Session Session Settings… (也可點擊工具欄中的 Rules 工具按鈕) 在打開的 [Data Compare – Session Settings] 對話框中,選擇 Columns 標籤頁: 在這個列表中,點選 [Left file] 列中要對齊的項(你的例子中,就是你所說的B列的列名),用 Move Up/Move Down 把它與 [Right file] 列中的相關項對齊,確定。 現在,在 Data Compare 兩側,你所說的B列的列序已經一致了。 然後,通過列標的右鍵菜單,把你的B列設為“Key Column”,把其餘各列設為“Standard Column”。 現在,兩側內容已經依據“Key Column”的內容進行了“行對齊”。 然後,點擊相應的工具欄按鈕: 關閉 Left Orphans 和 Right Orphans; 開啟 Same 和 Differences。 現在,Data Compare 兩側所剩的就是“B列相同的行”了。 然後,通過列標右鍵菜單中的“Hide Column”,隱藏你的B列。 現在,Data Compare 兩側剩下的就是你要的內容了。 你可以把兩側的內容複製到文本編輯器里。 也可以用 Session Data Compare Report… 輸出結果: [Data Compare Report] 的選項: Report layout: Side-by-side Report options: [Same, Differences] Output options: Plain text 然後,你在文本編輯器里對這個輸出結果稍加整理即可。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/242925.html