Hack Forums
[Java] Getting a NullPointerException - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Getting a NullPointerException (/showthread.php?tid=4421198)



Getting a NullPointerException - YellowMilk - Aug 29, 2014

I have the action of my button go to another class and keep getting null pointer exception error and I'm not sure how to fix it.

The button:
Code
        btnBasicSubmit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {

                try {

                    BasicDoxInput bdi = new BasicDoxInput();

                } catch (Exception ea) {
                    System.out.print(ea);
                }
            }
        });

The other class
Code
package prvt.lynx.manager;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class BasicDoxInput {

    public void BasicDoxInput() {
        Source s = new Source();

        String fullNameString = s.textFieldNameBasic.getText().toString();
        String aliasString = s.textFieldAliasBasic.getText().toString();
        String pictureString = s.textFieldPictureBasic.getText().toString();
        String ageString = s.textFieldAgeBasic.getText().toString();
        String genderString = s.textFieldGenderBasic.getText().toString();
        String locationString = s.textFieldGeneralLocBasic.getText().toString();
        String ipString = s.textAreaBasic.getText().toString();

        Object[] row = {fullNameString, "Basic Dox", s.ft.format(s.date)};
        s.tableModel.addRow(row);

        try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("", true)))) {

        }catch(IOException e1) {

        }
    }
}

I, also, seem to be having problems with the Embedded derby I'm trying to get for the program.

The error:
Code
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "returns" at line 1, column 31.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
    at prvt.lynx.manager.CreateDB.<init>(CreateDB.java:15)
    at prvt.lynx.manager.Source$2.run(Source.java:146)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$400(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$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)
Caused by: ERROR 42X01: Syntax error: Encountered "returns" at line 1, column 31.
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
    at org.apache.derby.impl.sql.compile.ParserImpl.parseStatementOrSearchCondition(Unknown Source)
    at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
    at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
    at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
    ... 18 more

The code:
Code
package prvt.lynx.manager;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.derby.jdbc.EmbeddedDataSource;

public class CreateDB {

    public CreateDB() throws SQLException {
        EmbeddedDataSource datasource = new EmbeddedDataSource();
        datasource.setDatabaseName("LynxDB");
        datasource.setCreateDatabase("create");
        Connection connection = datasource.getConnection();
        connection.createStatement().execute("create function BasicDoxInput " +    
                         "returns varchar " +
                         "language java " +
                         "parameter style java " +
                         "no sql " +
                         "external name 'prvt.lynx.manager.BasicDoxInput'");
    }

}



* - MrOrang - Aug 29, 2014

Check your sql queries. I think you mistyped something there.


* - Cosa Nostra - Aug 30, 2014

"returns" is a keyword. If you're not using it as a keyword, you can't use it as the word you're using it as.