Note that there are some explanatory texts on larger screens.

plurals
  1. POhow should I solve my NullPointerException?
    text
    copied!<p>I really don not know what else to do,I have searched every where,tried anything but could not solve my problem.I created a neo4j graph database and created an index on name property of nodes through localhost:7474(visually),now I want to get the node numbers by searching their name property index,but I get nullpointerexception error,I know this is because of existing a null value,and I know where is this from,but I can not solve it.</p> <p>this is the code:</p> <pre><code>package graph_traversing; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.graphdb.index.Index; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.Relationship; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.index.IndexHits; import org.neo4j.graphdb.index.IndexManager; public class search_string extends javax.swing.JFrame { public search_string() {initComponents(); } @SuppressWarnings("unchecked") private static enum RelTypes implements RelationshipType { INCLUDES } private static final String DB_PATH = "C:\\Users\\fereshteh\\Downloads\\Compressed\\neo4j-community-1.9.4\\DB"; GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH ); IndexManager nodeindex = db.index(); Index&lt;Node&gt; names = nodeindex.forNodes( "name" ); String [] str; Node [] nodes;Relationship rel; IndexHits&lt;Node&gt; hits; String find; // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt; private void initComponents() { jLabel1 = new javax.swing.JLabel(); search_txb = new javax.swing.JTextField(); search_btn = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jLabel1.setText(" Enter The Word Please"); search_btn.setText("Search"); search_btn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { search_btnActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(search_btn) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(search_txb, javax.swing.GroupLayout.PREFERRED_SIZE, 289, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(65, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(38, 38, 38) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(39, 39, 39) .addComponent(search_txb, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE) .addComponent(search_btn) .addGap(50, 50, 50)) ); pack(); }// &lt;/editor-fold&gt; private void search_btnActionPerformed(java.awt.event.ActionEvent evt) { str=search_txb.getText().split(" "); for(int i=0;i&lt;str.length;++i) { find=str[i]; hits = names.get("name", find); System.out.println(hits); nodes [i] = hits.getSingle(); // nodes [i]= nodeIndex.get( "name", find ).getSingle(); System.out.println(nodes[i]); } String s ="hi"; for(int i=0;i&lt;nodes.length;++i) { rel= (Relationship) nodes[i].getRelationships(); for(int j=i+1;j&lt;nodes.length;++j) { s=rel.toString(); } } System.out.println(s); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() {public void run() {new search_string().setVisible(true);} }); } // Variables declaration - do not modify private javax.swing.JLabel jLabel1; private javax.swing.JButton search_btn; private javax.swing.JTextField search_txb; // End of variables declaration } </code></pre> <p>the error firstly belongs to this line: <code>nodes [i] = hits.getSingle();</code></p> <p>I have changed it and <code>hits = names.get("name", find);</code> to so many other codes,but always get the error.</p> <p>and this is the error:</p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at graph_traversing.search_string.search_btnActionPerformed(search_string.java:90) at graph_traversing.search_string.access$000(search_string.java:14) at graph_traversing.search_string$1.actionPerformed(search_string.java:50) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3320) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:708) at java.awt.EventQueue$4.run(EventQueue.java:706) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91) </code></pre> <p>I have put <code>System.out.println(hits);</code> to understand whether hits is null or not,but I see in output hits have <code>org.neo4j.index.impl.lucene.LuceneIndex$1@481f3834</code> value(is this the right output?I expected to get the nodes).</p> <p>this is java api,and this will be really really kind of you if you help me,please,I have got dizziness.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload