Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4031334
Votes 0
Synopsis Program does not exit if awt.properties is loaded without a container
Category java:classes_awt
Reported Against 1.1beta3
Release Fixed
State 11-Closed, duplicate of 4030718, bug
Priority: 4-Low
Related Bugs 4030718
Submit Date 10-FEB-1997
Description




Below is a simple program. It takes one argument, but in this
revision the argument is ignored. It shows that if you create
an instance of an AWT subclass by itself, the program does not
exit completely. Ctrl-C must be used to stop it. This seems
to occur when making the new instance causes the message:
'Loading d:\JDK\JAVA\bin\..\lib\awt.properties'.
I came across
this problem while doing some beans stuff. I wish to instantiate
a bean. The Java Beans docs on page 88 say you simply use the
new constructor, which is what I am trying to do.

My real problem may be worse. It is intended that the argument
passed to this program will be a class name. I must convert
this class name dynamically to a class and create an instance of that
bean. In this case, I can not use the new constructor. Is
using newInstance() the recommended way?

-----
Case 1. Simply use the new constructor
----
package TestBeanReader;
import sun.demo.buttons.*;

	public class BeanProblem {

    public static void main(String args[]) {
	BeanProblem	beanProblem = new BeanProblem();

	beanProblem.start(args[0]);
    }
   
   public String start(String beanClassName) {
	OurButton ob = null;
	
	ob = new OurButton();	
	return "ok";
    }
   
}

---------
Case 2- Use the argument to make an instance. Only changing the start() method.
The argument has a ".class" extension.
This will probably be solved in the same way as Case 1.
-------
   public String start(String beanClassName) {
	Class beanClass = null;
	Object bean;
	
	try { beanClass = Class.forName(beanClassName.substring(0,beanClassName.length()-6)); }
	       catch (Exception ex) {System.out.println("Class not found"); return null;}
	if(beanClass == null) {System.out.println("The class was not found"); return null;}
	   try {bean = beanClass.newInstance();}
	       catch (Exception ex) {System.out.println("Can't make new instance"); return null;}
	return "ok";
    }


======================================================================
Work Around





======================================================================
Evaluation
Probably a dupe of 4030718.  
  xxxxx@xxxxx   2000-05-04
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang