لو سمحتوا ايه الخطأ فى هذا البرنامج
ممكن حد يدلنى على برامج معمولة كاملة بالجافا من فضلكم ....
A reference variable is null. Most commonly you forgot statements of the form: myArray = new int[10]; or myThing = new Thing(); See the array initialisation gotchas. These are the most common of runtime errors. Examine the stack trace to figure out where in the code it happening. That gives you a clue to get started. You can put some code of the form:
if (p = = null) System.out.println ("p was null" );
to narrow it down to the precise variable giving the trouble. Then you have to sit and think about why that variable is null. The real problem could be much earlier in the code, and the problem propagated through to the point where it eventually surfaced as an exception. You must figure out where it was supposed to be set, and have a look at that code and why it is failing. Most of the time you simply forgot to initialise. The easiest way to track the causes down is using a source lever debugger such as Visual Café or JBuilder. You can trace the flow of execution, or examine the state of the universe at the time of failure. If you don't have one, pepper your code with assertions to track down just what is null, e.g.
ensureNotNull(thing, "thing");
Your ensureNotNull method might print an error message if thing is null, then throw a new NullPointerException. By making ensureNotNull final, and using an if (debug) inside ensureNotNull, the inline expansions will have no overhead in production, and you can leave the debugging assertions in place to be reactivated later if ever needed.
Beware having two variable with the same name, one local and one instance, It is very easy to do inadvertently, and Java will not warn you e.g.
ArrayList thelist = new ArrayList( 149);
instead of
thelist = new ArrayList(149 );
You work with the local variable thinking you are working with the instance variable, and poof, your values are lost as soon as the local goes out of scope, leaving the instance version null. This is the way I most commonly create NullPointer exceptions for myself, when I convert a local variable to an instance one when I have to break a method up that uses the variable and forget to take out the local declaration.
Be very careful calling any methods inside your constructors. If subclasses override them, you will be invoking the subclass's version, which may be attempting to use fields that have not been initialised yet. You won't get a warning message! The problem usually shows up as puzzling NullPointerExceptions. The way out is to move code out of the constructor, often to the addNotify method. However, addNotify can get in analogous problem to the constructor since it too is overridden, and it may use overridden methods
الحياة كلها وقفة عز فقط
------------------------------------------
المجتمع معرفة و المعرفة قوة
اخى ahabdeen انت تقصد انى استدعيت فئة غير معرفة
للفصيلة
لأ اتا اقصد ان استدعيتها قبل ما تعرفها
يعنى المفروض
int i; i=0;
مش
i=0; int i;

<marquee>
مش موجود بصفة دايمة للامتحانات
</marquee>
هى عبارة فئه معرفة وانا بقوم بأستدعائها
public class Point {
int x;
int y;
Point(int xx,int yy){
x=xx;
y=yy;
}
}
هذا الموضوع مغلق.