开发者

null pointer exception in java servlet [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help cla开发者_StackOverflow社区rifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I got a "null pointer exception" fault in java servlet. Could someone tell me what happens? And how to avoid that?

I know java servlet can be used as part of a hybrid solution, could support many different programming languages. How would the different programs execute/call each other and exchange information? (could someone tell me some words but codes). In addition, values extracted from a session object have to be converted(cast) to a specific type, but why?

For example, how can I store a variable of type "int" in a session object. Could someone help me to figure it out?


I got a "null pointer exception" fault in java servlet. Could someone tell me what happens? And how to avoid that?

That happens when you're trying to access/invoke some reference which is actually null.

SomeObject someObject = null;
someObject.doSomething(); // Throws NullPointerException.

You need to make sure that you only access/invoke it when it is not null.

SomeObject someObject = null;
if (someObject != null) {
    someObject.doSomething(); // Won't throw NullPointerException.
}

It's just matter of logical thinking and understanding basic Java.


Another thing, I know java servlet can be used as part of a hybrid solution, could support many different programming languages. But how would the different programs execute/call each other and exchange information?(could someone tell me some words but codes).

Pass them as method parameter(s).


In addition, values extracted from a session object have to be converted(cast) to a specific type, but why? For example, how can I store a variable of type "int" in a session object. Could someone help me to figure it out?

Use Integer instead and/or profit Java 1.5's autoboxing capabilities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜