I have a simple setter method for a Java property and null is not appropriate for this particular property. I have always been torn, in this situation: should I throw ... |
When a Java VM crashes with an EXCEPTION_ACCESS_VIOLATION and produces an hs_err_pidXXX.log file, what does that indicate? The error itself is basically a null pointer exception. Is it always caused by ... |
Why String.indexOf do not use exception but return -1 when substring not found?
The purpose of this question is: when we start custom exception.
I believe avoid the need to return special error ... |
So I just spent around an hour trying to unveil and resolve a very strange bug, one that I have never seen before.
I am more or less asking for potential causes ... |
Java's e.printStackTrace() doesn't print all the details of the inner exception's stack trace.
Is there a ready way to generate the complete stack trace in string form? (besides formatting it myself)
Edit
I just ... |
I'm creating a java program that creates a file and fills it with data in string form with each field in the record limited to a specific length.
What I think I ... |
I always come across the same problem that when an exception is caught in a function that has a non-void return value I don't know what to return. The following code ... |
|
Is it better to return a null value or throw an exception from an API method?
Returning a null requires ugly null checks all over, and cause a major quality problem if ... |
What is better to use for Exception output message dynamic generation String or StringBuilder or StringBuffer?
|
I'm using JSON to deserialize an input string that contains a null value for certain hashmap property. Does anyone have any clue why this exception occurs ? Is it possible that ... |
So I have function that formats a date to coerce to given enum DateType{CURRENT, START, END}
what would be the best way to handling return value with cases that use switch ... |
I'm working on a Serpinski triangle program that asks the user for the levels of triangles to draw. In the interests of idiot-proofing my program, I put this in:
Scanner input= ...
|
I do a condition with a value when it is null and when it is not null.
The time where this value is null i got the java.lang.NullPointerException.
How could i deal with ... |
A colleague of mine sets reference to null in finally blocks. I think this is nonsense.
public Something getSomething() {
JDBCConnection jdbc=null;
try {
...
|
When doing null checks in Java code, and you throw IllegalArgumentExceptions for null values, what kind of message template do you use?
We tend to use something like this
public User getUser(String username){
...
|
I'm wondering about the cost of using a try/exception to handle nulls compared to using an if statement to check for nulls first.
To provide more information. There's a > 50% chance ... |
I have something similar to this.
void func() {
try {
//socket disconnects in middle of ..parsing packet..
} catch(Exception ex) {
if(!ex.getMessage().toString().equals("timeout") || !ex.getMessage().toString().equals("Connection ...
|
I have made a little program in java that accepts a string as a user input. Now i have made a dll writing its code in Visual C++. when i run ... |
I come to an API getStock designed, where I have no good judgment, on how I should deal with failure of operation.
The API will enable me to pass a stock code, ... |
I am new to java, and going to bite the bullet by asking what is I am sure, a dumb question. I created some methods, and simply wanted to call them ... |
Trying to use StackLL method size() is returning a null pointer error. I cannot figure out why this is, as count is initialized to 0. My only guess is that I ... |
Run time error on main method in MovieList.java.
I'm not sure my program design is fundamentally very good, but I'd like to know why it crashes. Thanks in advance.
package javaPractical.week3;
import javax.swing.*;
public class ...
|
I have this snippet of code to deal with catching particular exceptions
private static final String CONNECTION_REFUSED_EXCEPTION = "java.net.ConnectException: Connection refused: connect";
...
} catch (org.apache.axis.AxisFault af) {
...
|
I have the following code:
<#if !(task.dueDate??)><span class="datetime">Date: ${task.dueDate?string.medium_short!""}</span></#if>
It is supposed to protect from the situation in which dueDate is null but I still get the exception: Expression task.dueDate is undefined
Any ... |
Does anyone know why I am getting a null pointer error when I call the getResultSet() method from MyServ2 class
here is my DBClass (imports etc omitted)
public DBClass(){
...
|
Is it a bad practice to pass NULL argument to methods or in other words should we have method definitions which allow NULL argument as valid argument.
Suppose i want two method
1. ... |
I've already looked for the answer for this question, and I've found the following suggestions:
- If you are always expecting to find a value then throw the exception if it is missing. ...
|
I'm not sure of why this is happening, but I have a simple setup where a caller's return value is null.
I call a function which might throw registered exceptions. When it ... |
Can Java possibly throw UnsupportedEncodingException when using "UTF-8" encoding, or I can safely suppress it's throwing?
|
I have a similar problem.This is a snippet of my source:
FileWriter fstream = new FileWriter("results_for_excel.txt");
BufferedWriter writer = new BufferedWriter(fstream);
String sourceDirectory = "CVs";
File f = new File(sourceDirectory);
String[] filenames = f.list();
Arrays.sort(filenames);
String[] res = ...
|
For a little university project i'm doing, i need to extract code samples from html given as a string.
To by more precise, i need to get from that html string, everything ... |
I have a small program that is suppose to count lexemes. What I get is an erorr. I am fairly new to Java. Here is the error:
c:\programming>java LexemesTokenizer
input string: a = ...
|
JSON-Simple
JSON-Simple Example
String login = "{\"result\":[104192,42068],\"id\":1}";
Object obj = JSONValue.parse(login);
JSONArray array = (JSONArray)obj;
This throw a exception
Exception in thread "main"
java.lang.ClassCastException:
org.json.simple.JSONObject cannot be
cast ... |
In below code I am trying to do substring based on start and end index,But in end of the string.System is throwing ArrayIndexOutOfBoundsException. Please let me know, how to resolve this ... |
I need to get the output of ExceptionDescribe() in JNI as string so I can write it afterwards in a file instead of writing it directly on command line. Is there ... |
I wrote this little function just for practice, but an exception ("String index out of range: 29") is thrown and I don't know why...
(I know this isn't the best way to ... |
I have a method that sometimes throws an exception:
this.items[index] = element;
And I have a unit test that asserts that the exception that ought to be thrown is actually thrown:
try
{
...
|
Steps i perform to create dynamic class is as follows:
try
{
...
|
I am really stuck on this exception
private static void getUserComment(String s) {
while(s.contains("author'>")){
System.out.println(s.substring(s.indexOf("author'>"),
...
|
Here's the problem to solve: a method of a class that represents a gas network. This class manages objects of type Line that represent each single gas supply line.
An object ... |
I have a question related to String.format in JAVA.
My HibernateDao Class is responsible for persisting entities and will throw an exception in case I have any constrain violation. The message contains ... |
I have this code and when I run the script, I pass in valid parameters, but I keep on getting a NPE.
Help?
Code:
private static Date getNearestDate(List<Date> dates, Date currentDate) {
...
|
I'm getting a really annoying error, saying I'm getting a null pointer exception but there's an if statement to check to see if the text is null before proceeding:
...
|
I have the following code that reads in data from a file and stores it in a String variable, now when i run it, it gives me a string out of ... |
i'm getting this exception while getting a cell. This is what i'm doing:
if(versionToAdd.equals("15.6")) {
Cell X = ...
|
I have an array of JSON objects. To parse these arrays and store the simply data type values, I have to make assumptions of the key names and store them accordingly.
I ... |
I have a very simple method:
public int getScore() {
return game.gameWindow.userBestScore;
}
The problem is that it can happens that game object or gameWindow do not exist. I do not ... |
Inside my Java code, it is checking for !null condition and throwing an Exception.
For example
try
{
if (stud.getCall() != null)
acc.Call = stud.getCall().toString();
else
throw new Exception("Data is null");
}
catch (Exception e) {
logger.error("Some Error" + e.getMessage());
throw ...
|
I am in the early feasability phase of looking at use cases for a Corba client written in Java which will need to occasionally catch exceptions generated by the server implementation which may contain quite verbose summaries of the failure which occurred (basically a report). One way of tackling this might be to have the client set a state which requires ... |
Been prototyping an Alice - looking glass class, no Phd in cs or anything like that. Program intent is to look through files for unauthorized use of email in business environments, printing out: badWord : lineNumber : fileName : the actual line in the file where found. I got enough of the program working that I got word frequencies in a ... |
I believe Matcher.quoteReplacement() is for escaping the replacement string (the second argument in replaceAll()). To escape the target string (the first argument), use Pattern.quote() instead. Or you can use the new replace(CharSequence, CharSequence) in String, which treats both arguments literally (I think). Ugh. It's nice that they finally provided these methods, but putting them arbitrarily in different classes like that -ugh. ... |
Exception Null (Java in General forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java Java in General Exception Null Post by: rahul soni, Greenhorn on Oct 15, 2005 07:08:00 import java.sql.*; import javax.sql.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.crypto.Cipher; import java.security.Key; import javax.crypto.KeyGenerator; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; import java.security.InvalidKeyException; public class ... |
I'm doing a program for class. getting an average from acollection. We are using test Junits. one of the test involves null enteret into the collection. this causes a nullpointexception. I tried to use the try/catch thing to catch the null so it dosent crash the program but it dosen't work. Is there any way to deal with this thing so ... |
Hi Experts: I am working on a Minesweeper program, in a 3x3 grid. I have two major problems. First, I get a "java.lang.NullPointerException" at the statement "myApp.getPoint(e.getX(), e.getY());". I don't know why. Second, I have trouble getting my grid to divide up evenly. I have set up a Demension of 300x300 (html: |
Hello, I try to compare 2 strings, but when they are different, I get a nullpointer exception: Here is the method: try { query = "select * from BLEQUEUX.REGISTRATION where RG_REG_ID = "+regId; rs = dbMgr.executeQuery(query); while (ok && rs.next()) { String frame = rs.getString("RG_VEHICLE_FRAME"); String plaat = rs.getString("RG_VEHICLE_PLATE"); System.out.println("Frame "+frame+" == "+frameNo+" Plate "+plaat+" == "+plateNo+" ."); if (frame.equals(frameNo)) { ... |
The code to create an exception is correct. While you might want to construct an exception within a catch block, normally the main reason is to construct an exception of a different type, and rethrow it instead. For example: try { // ... } catch (NumberFormatException e) { throw new ApplicationSpecificException(e.getMessage()); } If you're using 1.4 or later, a better solution ... |
|
References are really pointers to objects. But where a pointer can be directly manipulated (the dreaded pointer arithmetics in C), references cannot. Because of that no special syntax is needed to dereference them, the runtime environment/compiler/JVM understands that a call to the reference means to address the memory structure in the memory space referenced by the reference and not the raw ... |
Your arguments for the substring function are the last index of "/" and the length of the string (note: you can omit this one; if you only pass one argument, the remainder of the string is returned). Now, if the "/" cannot be found, lastIndexOf returns -1. Now here's a question for you: where in your string is the "/"? Basically, ... |
|
Hello All, thanks for your helpful tips. I once again stumbled upon this index out of range exception. int[] encodeModulo; vob = new int[2]; String test = "Long string";// Length is 60 int q = 0; int j = pinCode.length(); int k = shortKey.length(); // length of shortKey is 60 int s1,s2,s3; StringBuffer cpt = new StringBuffer(); for(int i =0; i< ... |
|
I'm really confused. I'm trying to read a matrices from a text file, and I keep getting errors. The error always comes out in the last line of that for loop with the charAt(z) part. The error says: java.lang.StringIndexOutOfBoundsException: String index out of range: 0. I want to read each individual character in each row. Notes: I've already read the column ... |
2010-07-14 13:31:28,363 [TP-Processor3] ERROR com.scb.conflict.email.service.impl.EmailComposer. - java.lang.IndexOutOfBoundsException: No group 5 at java.util.regex.Matcher.group(Matcher.java:463) at java.util.regex.Matcher.appendReplacement(Matcher.java:730) at java.util.regex.Matcher.replaceAll(Matcher.java:806) at java.lang.String.replaceAll(String.java:2000) at com.scb.conflict.email.service.impl.EmailComposer.composePADSStatusChangeToApprovedEmail(EmailComposer.java:2333) at com.scb.conflict.common.service.impl.AuditTrailServiceImpl.retrieveStatusChangeEmail(AuditTrailServiceImpl.java:796) at com.scb.conflict.conflictsearch.action.ConflictSearchAction.updateConflictSearch(ConflictSearchAction.java:2204) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229) at com.scb.conflict.commo Also this is the getter function private String getStringValue(String str) { if (str != null) { return str.trim(); } else ... |
It's simple. If the object returned is truely an object that is that type, the type cast will succeed. However, in your example, I am very sure that the Thread object returned is *not* your class type -- as your class type is not a Thread class type. Hence, it is not possible for you to use it to start a ... |
Hi, here are routines i have written for encryption and decryption of string using key k, its giving me execption as javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipherdrd please help me out, to find error. thanks in advance. public static String chat_encrypt(String in,BigInteger k) { try { // Security.addProvider(new BouncyCastleProvider()); DHPrivateKeySpec d=new DHPrivateKeySpec(k,pg.p,new BigInteger("2")); DHPublicKeySpec ... |
sorry about the name. anyway. here is what i have so far. public String inputName() { String name = ""; String firstName = ""; String lastName = ""; boolean done = false; do { try { System.out.println("Enter first name: "); firstName = console.nextLine(); done = true; } catch (Exception exp) { System.out.println("Invaild input: Enter name in alpha characters"); System.out.println(); } } ... |
|
|
i am using this following code to compare to columns from two different tables but i am getting null point exception because some of my fields in columns Like first_name is empty in few rows!!! are empty!!! how can i go beyond those null values and could print whatever there in the database! my code!! SpySearchServlet.java Java Code: import javax.servlet.*; import ... |
Need help with program that has null exception in main This is my program The error happens during running the application after counting words. My teacher says I am calling an unwritten array but I have no idea how. please help :o import java.util.Scanner; import java.io.*; public class WordProcessing { public static void main (String [] args) throws IOException ... |
|
hey there, im a programmer thats new to the world of Java and im having an issue :S I'm trying to create a program, and it gives me the following error: " IllegalComponentStateException: contentPane cannot be set to null." i have no idea how i should be doin this, and dont know if its even possible the way ive programmed this ... |
Hello, As the title of the post says I'm wondering how to solve this problem with my code. I'm using netbeans and my goal is to open an image and then apply some effects (like blur, scale, etc). I have 5 classes: the frameimage (where I have the buttons), a class where I have the effects, a class for the JFilechooser ... |
I am writing a program that you have to enter either "R", "T", or "C" for some code to execute. I have everything running but cannot figure out how to handle if a different letter is entered or a number.....I want a reenter message to print and do again. I know how to use the numberFormat exception, but don't know how ... |
import java.util.Scanner; public class main { static String af; static String bf; public static void main(String args[]) { final double R = 1.0967 * (10000000); double lowest = Double.parseDouble(af); double highest = Double.parseDouble(bf); double answer; answer = R * (1 / (lowest * lowest) - 1 / (highest * highest)); System.out.println( "Insert the lowest Energy level"); Scanner obj = new Scanner(System.in); ... |
Various options. a) Fix the bug in your code where you called that method without providing customer details. b) If it's from user input, catch the exception, prompt the user to enter the missing data, and loop until it's all good. b) Alternatively, if it's from user input, validate the customer input and loop until it's all good before even calling ... |
i am working on the enchancement of the existing code. now we have to support utf16 format xml .So i found that parser is successfully parsing the xml but at the time of storing into the database(oracle9i), it is throwing "string index out of range:-8" exception.we are using store procedure for insert statement. If it is database issue then also our ... |
Yes, it will catch the exception whether you use 'throws Exception' or not. The difference is that, if you use 'throws Exception', the programmer will be forced to use a try-catch block in the caller method. If he does not do so, the code will not compile. If you don't use 'throws Exception', the programmer will not be force to use ... |
|
private class DrawListener implements MouseListener, MouseMotionListener { //-------------------------------------------------------------- /* Captures the initial position at which the mouse button is * */ public void mousePressed (MouseEvent event) { point1 = event.getPoint(); } /* *Gets the current position of the mouse as it is dragged and redraws the shape */ public void mouseDragged (MouseEvent event) { point2 = event.getPoint(); if (point1 != null ... |
|
I want the user only to put in the string"n" and catch any other errors. If the the user enters the string "n", the screen will print "i". In this case, what should i put for the catch statement? that's what i did: try { System.out.println("Enter n"); Scanner input = new Scanner (System.in); String word = input.nextLine(); } catch (Exception e){ ... |
|
Exception in thread "main" java.lang.NullPointerException at myclass2.launch(myclass2.java.29) at myclass2.main(myclass2.java:42) 1 import java.awt.*; 2 import java.awt.event.*; 3 class myclass2 implements ActionListener 4 { 5 private Frame[] f; 6 private Panel[] p; 7 private Label[] l; 8 private Button b; 9 private static int count; 10 11 myclass2() 12 { 13 count=0; 14 f=new Frame[5]; 15 p=new Panel[5]; 16 l=new Label[5]; 17 b=new ... |
If you look at the stack trace it tells you which line number it was trying to execute when the exception was thrown. I have a feeling it happens on the frame.repaint() line inside the mouse listener. You have a class-level GoFrame called "frame" and a local JFrame called "frame", and the wrong one is being referenced. I suggest picking different ... |
private void setIV() { char c = word.charAt(0); if ((c == 'a') || (c == 'A') || (c == 'e') || (c == 'E') || (c == 'i') || (c == 'I') || (c == 'o') || (c == 'O') || (c == 'u') || (c == 'U')) IV = true; else IV = false; } |
Do you know what a NullPointerException means? Perhaps that is the real >source of the problem. Yes, so I want to know if can do anything about the fact they should stay null (since they are waiting for input) and if I can still have try catch statements in my code. The first one was from a file called Double.java [r/o]. ... |
|
I'm using Netbeans. I go to run, set project configuration, and choose customize. Then I enter BlankFiller in the Main Class text field. In the arguments field, I enter fast red slower and clicked ok. So I've got 3 arguments in there that should be passed right? When I click run I still get the same output. |
|
1.import java.util.HashMap; 2. 3. 4.public class hash 5.{ 6//private HashMap phoneBook 7.private HashMap phoneBook= new HashMap(); // PhoneBook Object is local to hash class But u declared it as a instance 8 public hash() 9. { 10. //HashMap phoneBook= new HashMap(); *// PhoneBook Object is local to hash() constructor but not applicable to access on print() method. If u access the ... |
|
|
/** A subclass of BasicGame in which the computer asks the user to choose a * whole number from 1 to 100, inclusive. The program then makes a number of * guesses. After each guess, the user tells whether the guess is too high, * too low, or exactly right. Once the computer "knows" what the correct * number is, the ... |
Hi, Scenario:- Passing CLOB from Oracle function to Java method and parsing the CLOB received. I am trying to edit a CLOB that is passed from Oracle funtion to a Java method. while in process i am trying to store this CLOB object into a String variable. When the size of CLOB, that usually is between 100 - 600 Kb's, causes ... |
I'm glad you were able to find people willing to take the time to help you. However, you'll find in the future you'll get better, faster help if you're more forthcoming with details about what exactly you're doing and what exactly the problem was (full stack trace, clearly indicate which line caused the error, etc.). |
|
I am doing my code recently but I got an null point exception error when i tried to run it. Can anyone solve it for me? Thanks. Below is my code: public class MyArrayList { private ListItem[] container; private int size = 0; public MyArrayList() { container = new ListItem[10]; } public String toString() { String temp = "["; for (int ... |
|