Jump to content
Kyapo

Erro em Java, não sei como resolver

Recommended Posts

Kyapo

Boas,

Deparei'me com um problema aqui num programa em Java que estou a desenvolver durante o estágio (estou a fazer através do Eclipse), se possível gostava de poder encontrar uma solução com este post.

Vou começar apenas por colocar onde é detectado o erro com um comentário a dizer onde tenho o erro

for(i=0; i < NumNoticiasI; i++) 
		{
			Texto = roots[0] + "PainelFeeds\\Noticia" + i) + ".txt";
			try {
		    		BufferedReader in = new BufferedReader(new FileReader(Texto));
		    		String str;
		    		while ((str = in.readLine()) != null) 
		    		{
		    			Noticia[i] = str;            // <- é nesta linha que obtenho o erro
		    		}
		    		in.close();
				}
			catch (IOException i) {}
		}

Eu nunca meti uma dúvida em Java a partir de um forum, se precisarem de saber mais código digam, é que eu não ia estar aqui a meter tudo, é bastante :D

Share this post


Link to post
Share on other sites
magician

Convém saber que erro dá e o que é aquele Noticia.


I haven’t lost my mind; it’s backed up on DVD somewhere!

Share this post


Link to post
Share on other sites
Kyapo

Sim o erro que me esta a aparecer é na var Noticia.

Declaração da var

static String[] Noticia;

Erro

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at noticiasBD.Principal.actionPerformed(Principal.java:251)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Share this post


Link to post
Share on other sites
Kyapo

Já topei o erro, tinha a var mal declarada, de qualquer forma obrigado pela ajuda  :D

Share this post


Link to post
Share on other sites
magician

O array não está inicializado por isso não lhe podes adicionar.

Mais uma coisa só a nível de nota, por "norma" em Java nomes variáveis começam com letra minúscula e nomes de classes com letra maiúscula :D ajuda a visualizar o código mais rapidamente.


I haven’t lost my mind; it’s backed up on DVD somewhere!

Share this post


Link to post
Share on other sites
Kyapo

Realmente já me disseram isso várias vezes, mas é mesmo panca minha começar sempre com maiuscula :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.