Foros del Web » Programación para mayores de 30 ;) » Java »

porqué pasa esto?

Estas en el tema de porqué pasa esto? en el foro de Java en Foros del Web. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Java: Ver original package javaapplication2 ;   import java.io.PrintStream ;   public class JavaApplication2 {       public static final PrintStream ...
  #1 (permalink)  
Antiguo 07/08/2013, 13:37
Avatar de iivo94  
Fecha de Ingreso: febrero-2011
Ubicación: Argentina
Mensajes: 281
Antigüedad: 13 años, 2 meses
Puntos: 3
porqué pasa esto?

Código Java:
Ver original
  1. package javaapplication2;
  2.  
  3. import java.io.PrintStream;
  4.  
  5. public class JavaApplication2 {
  6.  
  7.     public static final PrintStream outa=null;
  8.     public static void main(String[] args) {
  9.         System.out.println("ASD");
  10.         JavaApplication2.outa.println("ASDDAS");
  11.     }
  12. }

me tira nullpointer exception en la linea donde uso mi nuevo objeto de printstream.
primero intente hacerlo sin poner =null, pero me tirabatambien nullpointerexception, pero enn java tambien esta declarado asi OUT, porque ami no me deja usar mi objeto de printstream pero si me deja usar el objeto out que esta igual declarado que outa? e.e
  #2 (permalink)  
Antiguo 07/08/2013, 15:37
 
Fecha de Ingreso: diciembre-2011
Mensajes: 152
Antigüedad: 12 años, 4 meses
Puntos: 34
Respuesta: porqué pasa esto?

Todo objeto necesita ser inicializado antes de ser utilizado, y el objeto out de la clase System también cumple con esta regla.
  #3 (permalink)  
Antiguo 07/08/2013, 15:41
Avatar de iivo94  
Fecha de Ingreso: febrero-2011
Ubicación: Argentina
Mensajes: 281
Antigüedad: 13 años, 2 meses
Puntos: 3
Respuesta: porqué pasa esto?

netbeans me dice que out esta asi:
public static final printstream out=null;

donde lo inicializa?
  #4 (permalink)  
Antiguo 07/08/2013, 16:14
 
Fecha de Ingreso: diciembre-2011
Mensajes: 152
Antigüedad: 12 años, 4 meses
Puntos: 34
Respuesta: porqué pasa esto?

Si verificas el código de la clase System (Openjdk) lo encontraras:
http://grepcode.com/file/repository....stem.java#1087

Código Java:
Ver original
  1. private static void More ...initializeSystemClass() {
  2. 1088        props = new Properties();
  3. 1089        initProperties(props);
  4. 1090        sun.misc.Version.init();
  5. 1091        FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
  6. 1092        FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
  7. 1093        FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
  8. 1094        setIn0(new BufferedInputStream(fdIn));
  9. 1095        setOut0(new PrintStream(new BufferedOutputStream(fdOut, 128), true));
  10. 1096        setErr0(new PrintStream(new BufferedOutputStream(fdErr, 128), true));
  11. 1097
  12. 1098        // Load the zip library now in order to keep java.util.zip.ZipFile
  13. 1099        // from trying to use itself to load this library later.
  14. 1100        loadLibrary("zip");
  15. 1101
  16. 1102        // Setup Java signal handlers for HUP, TERM, and INT (where available).
  17. 1103        Terminator.setup();
  18. 1104
  19. 1105        // The order in with the hooks are added here is important as it
  20. 1106        // determines the order in which they are run.
  21. 1107        // (1)Console restore hook needs to be called first.
  22. 1108        // (2)Application hooks must be run before calling deleteOnExitHook.
  23. 1109        Shutdown.add(sun.misc.SharedSecrets.getJavaIOAccess().consoleRestoreHook());
  24. 1110        Shutdown.add(ApplicationShutdownHooks.hook());
  25. 1111        Shutdown.add(sun.misc.SharedSecrets.getJavaIODeleteOnExitAccess());
  26. 1112
  27. 1113        // Initialize any miscellenous operating system settings that need to be
  28. 1114        // set for the class libraries. Currently this is no-op everywhere except
  29. 1115        // for Windows where the process-wide error mode is set before the java.io
  30. 1116        // classes are used.
  31. 1117        sun.misc.VM.initializeOSEnvironment();
  32. 1118
  33. 1119        // Set the maximum amount of direct memory.  This value is controlled
  34. 1120        // by the vm option -XX:MaxDirectMemorySize=<size>.  This method acts
  35. 1121        // as an initializer only if it is called before sun.misc.VM.booted().
  36. 1122        sun.misc.VM.maxDirectMemory();
  37. 1123
  38. 1124        // Set a boolean to determine whether ClassLoader.loadClass accepts
  39. 1125        // array syntax.  This value is controlled by the system property
  40. 1126        // "sun.lang.ClassLoader.allowArraySyntax".  This method acts as
  41. 1127        // an initializer only if it is called before sun.misc.VM.booted().
  42. 1128        sun.misc.VM.allowArraySyntax();
  43. 1129
  44. 1130        // Subsystems that are invoked during initialization can invoke
  45. 1131        // sun.misc.VM.isBooted() in order to avoid doing things that should
  46. 1132        // wait until the application class loader has been set up.
  47. 1133        sun.misc.VM.booted();
  48. 1134
  49. 1135        // The main thread is not added to its thread group in the same
  50. 1136        // way as other threads; we must do it ourselves here.
  51. 1137        Thread current = Thread.currentThread();
  52. 1138        current.getThreadGroup().add(current);
  53. 1139
  54. 1140        // Allow privileged classes outside of java.lang
  55. 1141        sun.misc.SharedSecrets.setJavaLangAccess(new sun.misc.JavaLangAccess(){
  56. 1142            public sun.reflect.ConstantPool More ...getConstantPool(Class klass) {
  57. 1143                return klass.getConstantPool();
  58. 1144            }
  59. 1145            public void More ...setAnnotationType(Class klass, AnnotationType type) {
  60. 1146                klass.setAnnotationType(type);
  61. 1147            }
  62. 1148            public AnnotationType More ...getAnnotationType(Class klass) {
  63. 1149                return klass.getAnnotationType();
  64. 1150            }
  65. 1151            public <E extends Enum<E>>
  66. 1152                    E[] More ...getEnumConstantsShared(Class<E> klass) {
  67. 1153                return klass.getEnumConstantsShared();
  68. 1154            }
  69. 1155            public void More ...blockedOn(Thread t, Interruptible b) {
  70. 1156                t.blockedOn(b);
  71. 1157            }
  72. 1158        });
  73. 1159    }
  #5 (permalink)  
Antiguo 07/08/2013, 16:24
Avatar de iivo94  
Fecha de Ingreso: febrero-2011
Ubicación: Argentina
Mensajes: 281
Antigüedad: 13 años, 2 meses
Puntos: 3
Respuesta: porqué pasa esto?

que es eso de private static initializeSystemclass,

no era que los inicializadores de clase eran un static{} asi seco? eso de arriba es un inicializador de clase? ahgracias me sirvio mucho

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:25.