|
Torsten makes a very valid point. I always think it is best at first to spend some time just watching the forums and looking at the answers posted by some of the regulars to see what the general protocol is. That way we can try and maintain a consistent way of responding to people. I know it can be confusing when you start (I made (and still make) plenty of mistakes) but it is time well spent.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
hi friends...
i am getting the following error while doing a program.....its a runtime error....can u please suggest a solution...also please tell me the reason for the same so that won't repeat the same next time also..
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at testThread.main(testThread.java:78)
My code is as following:
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
class testThread extends Frame implements ActionListener,Runnable
{
int lower,upper;
Label l1=new Label("ODD");
Label l2=new Label("EVEN");
List lb1=new List();
List lb2=new List();
Button b2=new Button("EXIT");
void test(int low,int up)
{
lower = low;
upper = up;
setLayout(new FlowLayout());
setSize(700,700);
setTitle("Thread Demo");
setVisible(true);
add(l1);add(lb1);add(l2);add(lb2);add(b2);
b2.addActionListener(this);
Thread t=new Thread(this);
t.start();
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0); }
}
);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
System.exit(0);
}
public void run()
{
try
{
if((lower % 2) != 0)
{
lower = lower + 1;
}
while(lower <= upper)
{
Thread.sleep(1000);
lb2.add(String.valueOf(lower));
lower += 2;
Thread.sleep(500);
}
}catch(Exception e){}
}
public static void main(String[] args)
{
testThread obj=new testThread();
int lower,upper;
lower = Integer.parseInt(args[0]);
upper = Integer.parseInt(args[1]);
obj.test(lower,upper);
if((lower % 2) == 0)
{
lower = lower + 1;
}
try
{
while(lower <= upper)
{
Thread.sleep(1000);
obj.lb1.add(String.valueOf(lower));
lower = lower + 2;
Thread.sleep(500);
}
}
catch(Exception e){}
}
}
|
|
|
|
|
- do you use eclipse? it is able to debug and shows you where you get stuck.
Your code works here. be shure to give arguments to the programm - first int low, second int a high number. it does not validate, if the arguments are in right order.
regards
Torsten
I never finish anyth...
|
|
|
|
|
i am not using eclipse ..i want that to be run from command prompt...can u suggest a change in code that could rectify the error....
|
|
|
|
|
"ArrayIndexOutOfBoundsException" says, that you try to read a value that does not exist from an array.
"ArrayIndexOutOfBoundsException: 0" says the first value does not exist (computers and all creatures except mankind do intend to count from 0!).
The only array i can see in your code is the argument array the main-method needs. So you're probably not giving the arguments to your app.
Please use eclipse or netbeans. it will enhance your code and make it easier for you to program.
regards,
Torsten
I never finish anyth...
|
|
|
|
|
now its clear Torsten.....thanks for ur suggestion too....
|
|
|
|
|
hi....
Let me tell firstof all that i am a beginner in Java ,can anyone help me to understand the following piece of code...also to elaborate this class a bit so as to get an output...
class A
{
int a;
A()
{
this(10);
}
A(int x)
{
a=x;
}
}
|
|
|
|
|
Firstly, can you add <pre> tags around your code so that can be read easily.
What you have is class A that has one member variable a and two constructors.
The default constructor A() simply delegates to the constructor taking an argument A(int x) .
Example usages would be:
A a1 = new A();
A a2 = new A(10);
A a3 = new A(42);
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thanks Vilmos....
But can u make the second line a bit more clear.....
ie:
"The default constructor A() simply delegates to the constructor taking an argument A(int x)."
|
|
|
|
|
A constructor can be called just like a function so the line in the default constructor below:
A()
{
this(10);
}
merely calls the constructor that takes an integer parameter and sets the member variable to the value 10. Take a look at The Java Tutorials[^] for more information.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Thanks Richard...
Now its clear.....
|
|
|
|
|
class A
{
int a;
A()
{
this(10);
}
A(int x)
{
a=x;
}
public int somemethod(int value){
return (x*value);
}
Try to make your work easier by giving full classified names to objects, members and methods. and formate the code. make comments - feel free to express you.
regards,
Torsten
I never finish anyth...
|
|
|
|
|
Thanks,Torsten....
Its clear now....
|
|
|
|
|
Hello,
I have the following problem :
- I have a class My frame that extends JFrame and
also I have a class MyComponent that extends JComponent
- the MyComponent class overrides the paint method and displays a picture on a certain position
The problem is that when I call in the MyFrame constructor the methods (inherited from JFrame )
add(new MyComponent( ...position parameters 1.. ))
and also
add(new MyComponent( ...position parameters 2.. ))
only the last one is displayed (if I add more only the last one is drawn).
I spoke to someone and told me that I could be that the frame draws the components on different layers but didn't knew how to solve it ... .I've googled it and still nothing .
If someone had this issue please reply.
Thanks in advance!
|
|
|
|
|
In your overridden paint method, you need to repaint ALL the components not just the alst one added.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
|
Still nothing.
I'ved tried the following:
this are all in the class constructor that extends JFrame
1)
add(new MyComponent(0,0,50,50,12));
add(new MyComponent(100,100,50,50,12));
2)
this.getContentPane().add(new MyComponent(0,0,50,50,12));
this.getContentPane().add(new MyComponent(100,100,50,50,12));
this.repaint();
and only the second component was drawn in both cases. However if I omit comment the second component, the first one is drawn correctly.
My component extends JComponent and overrides paint method by painting a image at the specified coordinates.
|
|
|
|
|
|
Hi:
I am deploying Glassfish 2.1.1 with J2EE 1.4. The project compiles-builds successfully. But it fails to deploy and open in the browser. The error from the log is:
com.sun.enterprise.config.ConfigException: I/O error while loading deployment descriptor for: hello2
caused by
Caused by: java.io.FileNotFoundException: C:/eepassion/UnZip/servletbasics/samples/hello2/build/web
I have looked in the web folder and there is an web folder. But do not know what I'm looking for. Your suggestion would be very helpful.
Lin
|
|
|
|
|
The message seems fairly clear, Java is looking for a file or directory which does not exist, as described in the message. Or possibly there is a permission issue and the program cannot access that folder.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Or possibly there is a permission issue and the program cannot access that folder.
often seen since Windows7 - check if your SDK/involved Programms is marked "run as Admin".
regards
Torsten
I never finish anyth...
|
|
|
|
|
Well I understand that, which is why I suggested it to the OP!
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I am trying to process data by servlet sended by jsp form using AJAX..... with 'GET' method its working okey ... but using 'POST' method to do this creating problem that onreadystatechage condition not exectue at (xmlhttp.readyState==4 && xmlhttp.status==200)
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 || xmlhttp.status==200) {
alert("state=4 OR 200");
document.getElementById("TextChatHistory").value = xmlhttp.responseText;
}
}
i tryed to solve this too much .... but i cant .... Any one plz help me ..... THANK ...
COMPLETE PROGRAM CODE IS GIVEN BELOW,
JSP_CODE
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%--@page import="java.util.Timer.*, java.util.TimerTask.*"
Timer timer;
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript" >
function AjaxFunction() {
xmlhttp = null;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 || xmlhttp.status==200) {
alert("state=4 OR 200");
document.getElementById("TextChatHistory").value = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "TextChat", true);
var Parameter_MsgSType = "msgText=" + document.getElementById("msgText").value;
alert(Parameter_MsgSType);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-lenght", Parameter_MsgSType.lenght);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(Parameter_MsgSType);
alert("Ajax fuinction finished");
}
</script>
</head>
<body>
<!--<h1>Hello JSP!</h1>-->
<div id="myText"></div> <!--for testing...-->
<form name="TextChat" method="post" action="" >
<textarea cols="50" rows="10" readonly id="TextChatHistory" name="TextChatHistory" >TextChat History</textarea>
<br />
<textarea cols="50" rows="3" id="msgText" >Enter Text</textarea>
<select name="SentToType">
<option value="p">Presentor</option>
<option value="h">Host</option>
<option value="a">Attendee</option>
<option value="l">All</option>
</select>
<input type="submit" value="SEND" onclick="AjaxFunction()" />
</form>
</body>
</html>
|
|
|
|
|
give me solution of Round robin scheduling code in java
|
|
|
|
|
Ask yourself this: Where would be a good place to search for something that fits my requirements?
This forum tends not to hand out ready made solutions on demand, try doing some research first, and come back here when you have a technical query.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|