简体   繁体   English

Netbeans“非法启动类型”错误

[英]Netbeans “illegal start of type” error

I am following the Netbeans CRUD Application tutorial (modified to use my own database) and I am getting this error that I can't figure out at all. 我正在跟踪Netbeans CRUD应用程序教程(已修改为使用我自己的数据库),但遇到了我根本无法弄清的错误。

The error says "illegal start of type ';' 错误显示为“类型';'的非法开始”。 expected, cannot find symbol 预期,找不到符号

This is my code: 这是我的代码:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.photo.viewer;

import demo.Photos;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.NbBundle.Messages;
import org.openide.windows.TopComponent;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(
        dtd = "-//com.photo.viewer//photoViewer//EN",
        autostore = false
)
@TopComponent.Description(
        preferredID = "photoViewerTopComponent",
        //iconBase="SET/PATH/TO/ICON/HERE", 
        persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
@TopComponent.Registration(mode = "explorer", openAtStartup = true)
@ActionID(category = "Window", id = "com.photo.viewer.photoViewerTopComponent")
@ActionReference(path = "Menu/Window" /*, position = 333 */)
@TopComponent.OpenActionRegistration(
        displayName = "#CTL_photoViewerAction",
        preferredID = "photoViewerTopComponent"
)
@Messages({
    "CTL_photoViewerAction=photoViewer",
    "CTL_photoViewerTopComponent=photoViewer Window",
    "HINT_photoViewerTopComponent=This is a photoViewer window"
})
public final class photoViewerTopComponent extends TopComponent {

    public photoViewerTopComponent() {
        initComponents();
        setName(Bundle.CTL_photoViewerTopComponent());
        setToolTipText(Bundle.HINT_photoViewerTopComponent());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(129, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(200, Short.MAX_VALUE))
        );
    }// </editor-fold>                        

    // Variables declaration - do not modify                     
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration                   
    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
    EntityManager entityManager = Persistence.createEntityManagerFactory("catalogueLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Photos.findAll");
List<Photos> resultList = query.getResultList();
for (Photos c : resultList) {
  jTextArea1.append(c.getTitle() + " (" + c.getLocation() + ")" + "\n");
} 
}

The error is in the 4th last line: 错误在最后4行:

for (Photos c : resultList) {
      jTextArea1.append(c.getTitle() + " (" + c.getLocation() + ")" + "\n");
    } 

I know it is something simple but I cannot figure out what or how to fix it. 我知道这很简单,但是我无法弄清楚该如何解决。 I am sure it is a misplaced ';' 我确定这是放错位置的';' or something? 或者其他的东西?

As you are no doubt aware I am new to Java. 毫无疑问,您是Java的新手。

I have done everything the tutorial says but can't seem to figure this out... 我已经完成了本教程所说的一切,但似乎无法弄清楚……

Any help would be grand! 任何帮助将是巨大的!

Thanks 谢谢

I think you missed the method block..May be you would like to wrap below block of code in some method. 我认为您错过了方法块。可能是您希望在某些方法中包装下面的代码块。

   EntityManager entityManager = Persistence.createEntityManagerFactory("catalogueLibraryPU").createEntityManager();
   Query query = entityManager.createNamedQuery("Photos.findAll");
   List<Photos> resultList = query.getResultList();
   for (Photos c : resultList) {
   jTextArea1.append(c.getTitle() + " (" + c.getLocation() + ")" + "\n");
  } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM