Erro ao implementar Singleton

7 respostas
victorgilc

Eai galera!

tenho o seguinte erro ao tentar implementar um singleton num internalframe q não pode repetir
o q pode ser?

run:
Exception in thread "AWT-EventQueue-0" java.lang.Error: java.lang.reflect.InvocationTargetException
        at org.jdesktop.application.ApplicationAction.actionFailed(ApplicationAction.java:859)
        at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:665)
        at org.jdesktop.application.ApplicationAction.actionPerformed(ApplicationAction.java:698)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
        at org.jdesktop.swingx.JXHyperlink.fireActionPerformed(JXHyperlink.java:264)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6267)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6032)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Window.dispatchEventImpl(Window.java:2478)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.jdesktop.application.ApplicationAction.noProxyActionPerformed(ApplicationAction.java:662)
        ... 27 more
Caused by: java.lang.RuntimeException: Uncompilable source code
        at exproperties.ExPizza.caracteristicas(ExPizza.java:154)
        ... 32 more

7 Respostas

viniciusalvess
public class Teste{

private Teste INSTANCIA = new Teste();
    private Teste(){
    }

    public static Teste show(){
    return INSTANCIA ;

   }

}
ViniGodoy

Por que diabos vc tá usando reflection?

victorgilc

:shock: - boa pergunta hein…

M

Caused by: java.lang.RuntimeException: Uncompilable source code at exproperties.ExPizza.caracteristicas(ExPizza.java:154) ... 32 more

Pode postar a classe exproperties.ExPizza aqui?

victorgilc

la vai

package exproperties;

import com.sun.swingset3.DemoProperties;
import javax.swing.JInternalFrame;

import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.ApplicationActionMap;
import org.jdesktop.swingx.JXTaskPane;

/**
 *
 * @author victor
 */
@DemoProperties(value = "Aplicativos",
category = "",
description = "Descrição da barra de menus",
sourceFiles = {
    "exproperties/ExPizza.java", "exproperties/resources/ExPizza.properties"
})
public class ExPizza extends javax.swing.JFrame {

    private JXTaskPane PrimeiroGroup;
    private JXTaskPane SegundoGroup;
    private JXTaskPane TerceiroGroup;

    public ExPizza() {
        initComponents();
        createTaskPane();
        bind();
        pack();
        Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(this);
      }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jXTPContainerTeste = new org.jdesktop.swingx.JXTaskPaneContainer();
        desk = new javax.swing.JDesktopPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Formulario");

        jXTPContainerTeste.setName("jXTPContainerTeste"); // NOI18N

        desk.setEnabled(false);
        desk.setName("desk"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXTPContainerTeste, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(desk, javax.swing.GroupLayout.PREFERRED_SIZE, 419, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(desk, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE)
                    .addComponent(jXTPContainerTeste, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 244, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>                        
    private void createTaskPane() {
        PrimeiroGroup = new JXTaskPane();
        PrimeiroGroup.setName("PrimeiroGroupteste");
        jXTPContainerTeste.add(PrimeiroGroup);

        SegundoGroup = new JXTaskPane();
        SegundoGroup.setName("SegundoGroupteste");
        jXTPContainerTeste.add(SegundoGroup);

        TerceiroGroup = new JXTaskPane();
        TerceiroGroup.setName("TerceiroGroupteste");
        jXTPContainerTeste.add(TerceiroGroup);
    }

    private void bind() {
        ApplicationActionMap map = Application.getInstance().getContext().getActionMap(this);

        PrimeiroGroup.add(map.get("caracteristicas"));

        SegundoGroup.add(map.get("cliente"));

        TerceiroGroup.add(map.get("entrega"));
    }

    @Action
    public void caracteristicas()
    {
        internalPizza primeiroIFrame = (internalPizza) new JInternalFrame();

        desk.add(primeiroIFrame);
        primeiroIFrame.setVisible(true);
        primeiroIFrame.setBounds(10,10,400,200);
        primeiroIFrame.setClosable(true);
    }
   

    @Action
    public void cliente() 
    {
        internalDadosCliente segundoIFrame = new internalDadosCliente();

        desk.add(segundoIFrame);
        segundoIFrame.setVisible(true);
        segundoIFrame.setBounds(10,10,400,200);
        segundoIFrame.setClosable(true);
    }

    @Action
    public void entrega() 
    {
        internalDadosEntrega terceiroIFrame = new internalDadosEntrega();

        desk.add(terceiroIFrame);
        terceiroIFrame.setVisible(true);
        terceiroIFrame.setBounds(10,10,400,200);
        terceiroIFrame.setClosable(true);
    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ExPizza().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JDesktopPane desk;
    private org.jdesktop.swingx.JXTaskPaneContainer jXTPContainerTeste;
    // End of variables declaration                   
}
M
internalPizza primeiroIFrame = (internalPizza) new JInternalFrame();

Se o construtor da classe interalPizza for privado isso pode gerar problemas.

victorgilc

Consegui resolver :smiley: :smiley: :smiley:

por aí:
http://guj.com.br/posts/list/124079.java#671471

thanks man

Criado 6 de dezembro de 2010
Ultima resposta 7 de dez. de 2010
Respostas 7
Participantes 4