Bonjour à tous

je test un petit programme de de chargement de classe mais lors de la compilation le message suivant s'affiche "class, interface, or enum expected"
et il m'indique l'erreur dans cette partie du code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
public Class findClass (String name) throws ClassNotFoundException
{
	try
	{
		File file=new File("titi", name+".class");
		InputStream is= new FileInputStream(file);
		int l=(int)file.length();
		byte b[] = new byte [length];
		is.read(b);
		return defineClass(name,b,0,length);
	}
	catch (Exception e)
	{
		throw new ClassNotFoundException(name);
	}
}
quelqu'un a une idée ? merci

Bonjour

Excuse-moi mais j'ai pas compris ta remarque. En faite voici mon programme.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
 
/**
 * @(#)Test.java
 *
 *
 * @author 
 * @version 1.00 2010/9/27
 */
import java.io.File;
	import java.io.*;
 import java.io.FileInputStream;
  import java.lang.reflect.Method;
   import java.net.URLClassLoader;
    import java.net.URL; 
 
public  class Test extends ClassLoader 
{
 
private String name;
 
    public Test(String name) 
    	{
    		this.name=name;
    	}
    public void finalize()
    {
    	System.out.println("destroy all calsee");
    }	
    	public String toString()
    	{
    		return "ClassLoader<"+name+">";
 
    	}
 
    public static void main (String arg[]) throws Exception
    {
    	(new Test("one")).loadClass("Titi").getDeclaredMethod("f").invoke(null);
    	(new Test("two")).loadClass("Titi").getDeclaredMethod("f").invoke(null);
    	System.gc();
    }
 
}
 
 public Class findClass (String name) throws ClassNotFoundException
{
	try
	{
		File file=new File("titi", name+".class");
		InputStream is= new FileInputStream(file);
		int l=(int)file.length();
		byte b[] = new byte [length];
		is.read(b);
		return defineClass(name,b,0,length);
	}
	catch (Exception e)
	{
		throw new ClassNotFoundException(name);
	}
}
 
 class Titi 
{
	public static int a=0;
	public static void f()
	{
		System.out.println("in f a is "+ a++);
		new Toto();
	}
 
}
  class Toto 
{
	public Toto()
	{
		System.out.println("---Classloader tree----");
		for(ClassLoader cur=getClass().getClassLoader();cur!=null;cur=cur.getParent())
			System.out.println("   "+cur);
 
			System.out.println("primordial");
	}
}
je me suis aperçu de mon erreur merci.