Reputation: 289
I have some problems with JavaFX exceptions. My project works in my Eclipse, but now my friend is trying to access the project also. We have shared and save directly to a dropbox folder. But he can't get it to work at all. He get this error in the console. Would really really appriciate some explaining of what this means.. :)
jun 12, 2014 9:19:37 EM application.Main gotoLogin
SEVERE: null
javafx.fxml.LoadException:
/C:/Users/Administrator/Dropbox/Project%20BlueRift/bin/application/LoginGUI.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at application.Main.replaceSceneContent(Main.java:53)
at application.Main.gotoLogin(Main.java:68)
at application.Main.start(Main.java:39)
at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at application.DBManager.connect(DBManager.java:54)
at controllers.LoginController.initialize(LoginController.java:48)
... 16 more
DB Connect:
package application;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.DatabaseMetaData;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;
import controllers.IReportStatus;
public class DBManager {
private static DBManager INSTANCE;
private final String MYSQL_URL = "jdbc:mysql://213.65.171.115:3306";
private final String MYSQL_DATABASE = "/bluerift";
private final String MYSQL_USER = "test";
private final String MYSQL_PW = "test";
private String CURRENT_USER = null;
private String CURRENT_TIMELINE = null;
private Connection conn = null;
private Statement st = null;
private ResultSet rs = null;
private PreparedStatement preparedStatement = null;;
private DatabaseMetaData dbm = null;
private IReportStatus reportStatus;
private DBManager() {
}
public boolean connect() {
try {
if (conn != null) {
return true;
}
Class.forName("com.mysql.jdbc.Driver");
conn = (Connection) DriverManager.getConnection(MYSQL_URL
+ MYSQL_DATABASE, MYSQL_USER, MYSQL_PW);
st = (Statement) conn.createStatement();
dbm = (DatabaseMetaData) conn.getMetaData();
System.out.println("DevCon: Connected");
return true;
}
catch (Exception ex) {
reportStatus.setMsg("Could not reach database.");
conn = null;
st = null;
rs = null;
return false;
}
}
public boolean userLogin(String aUserName, String aPassword) {
aUserName = aUserName.trim();
if (aUserName.isEmpty()) {
reportStatus.setMsg("Empty Username");
return false;
}
if (aUserName.contains(" ")) {
reportStatus.setMsg("Username can not contain whitespaces");
return false;
}
if (aPassword.isEmpty()) {
reportStatus.setMsg("Empty Password");
return false;
}
try {
String query = "SELECT userName,userPassword FROM users";
rs = st.executeQuery(query);
while (rs.next()) {
if (rs.getString("userName").equals(aUserName)) {
if (rs.getString("userPassword").equals(aPassword)) {
System.out.println("DevCon: User "
+ MyUtil.quote(aUserName) + " logged in");
CURRENT_USER = aUserName;
return true;
}
else {
reportStatus.setMsg("Wrong Password");
return false;
}
}
}
reportStatus.setMsg("Username not found in database");
return false;
}
catch (Exception ex) {
reportStatus.setMsg("Could not reach database.");
conn = null;
st = null;
rs = null;
return false;
}
}
public boolean userRegister(String aName, String aPassword,
String confirmPassword, String aEmail) {
aEmail = aEmail.trim();
aName = aName.trim();
if (aName.length() < 5 || aName.length() > 25) {
reportStatus
.setMsg("Username has to be between 5 and 25 characters long");
return false;
}
if (!MyUtil.isAlphaNumericUs(aName)) {
reportStatus
.setMsg("Username can only contain a-Z, A-Z, 0-9 and _");
return false;
}
if (aEmail.isEmpty()) {
reportStatus.setMsg("Email can not be empty");
return false;
}
if (!MyUtil.isVaildEmail(aEmail)) {
reportStatus.setMsg("Email incorrect");
return false;
}
if (aPassword.length() < 5 || aPassword.length() > 30
|| confirmPassword.length() < 5
|| confirmPassword.length() > 30) {
reportStatus
.setMsg("Password must be between 5 and 30 characters long");
return false;
}
if (!aPassword.equals(confirmPassword)) {
reportStatus.setMsg("Password does not match");
return false;
}
try {
String query = "SELECT userName, userEmail FROM users";
rs = st.executeQuery(query);
while (rs.next()) {
if (aName.equals(rs.getString("userName"))) {
reportStatus.setMsg("Username already registred");
return false;
}
if (aEmail.equals(rs.getString("userEmail"))) {
reportStatus.setMsg("Email already registred");
return false;
}
}
query = "INSERT INTO users (userName, userPassword, userEmail)"
+ " VALUES (?, ?, ?)";
preparedStatement = (PreparedStatement) conn
.prepareStatement(query);
preparedStatement.setString(1, aName);
preparedStatement.setString(2, aPassword);
preparedStatement.setString(3, aEmail);
preparedStatement.execute();
}
catch (Exception ex) {
System.out.println("Error: " + ex);
return false;
}
return true;
}
public boolean createTimeline(String timelineName) {
timelineName = timelineName.trim();
if (timelineName.length() < 3 || timelineName.length() > 15) {
reportStatus
.setMsg("Name must be between 3 and 15 characters long");
return false;
}
System.out.println("timeline name in: " + timelineName);
if (!MyUtil.isAlphaNumeric(timelineName) || timelineName.isEmpty()) {
reportStatus
.setMsg("Invaild timeline name. Allowed symbols are a-z, A-Z and 0-9");
return false;
}
if (timelineExists(timelineName)) {
reportStatus.setMsg("Timeline called " + MyUtil.quote(timelineName)
+ " already exists");
return false;
}
else {
String query = "CREATE TABLE `bluerift`.`"
+ getCurrentUser()
+ "-"
+ timelineName
+ "` (`id` INT NOT NULL AUTO_INCREMENT,`eventName` VARCHAR(45) NULL,`eventYear` INT NULL,`eventDesc` LONGBLOB NULL,PRIMARY KEY (`id`));";
try {
st.executeUpdate(query);
} catch (SQLException e) {
e.printStackTrace();
}
}
return true;
}
public ObservableList<String> receiveTimelines() {
ObservableList<String> temp = FXCollections.observableArrayList();
try {
rs = dbm.getTables(null, null, "%", null);
while (rs.next()) {
if (rs.getString(3).contains(getCurrentUser() + "-")) {
temp.add(rs.getString(3).substring(
getCurrentUser().length() + 1));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return temp;
}
private boolean timelineExists(String t) {
try {
rs = dbm.getTables(null, null, CURRENT_USER + "-" + t, null);
if (rs.next()) {
return true;
}
}
catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public void deleteTimeline(String timelineName) {
try {
String query = "DROP TABLE `bluerift`.`" + getCurrentUser() + "-"
+ timelineName + "`;";
st.executeUpdate(query);
} catch (SQLException e) {
e.printStackTrace();
}
}
public String getCurrentUser() {
if (CURRENT_USER == null) {
return "DevCon: No user online";
}
return CURRENT_USER;
}
public void userLogout() {
if (CURRENT_USER != null) {
System.out.println("DevCon: User " + CURRENT_USER + " logged out");
CURRENT_USER = null;
}
else {
System.out.println("DevCon: No user online");
}
}
public void setReportTo(IReportStatus reportStatus) {
System.out.println("new ReportStatus is: " + reportStatus);
this.reportStatus = reportStatus;
}
public String getCurrentTimeline() {
return CURRENT_TIMELINE;
}
public static DBManager getInstance() {
if (INSTANCE == null) {
INSTANCE = new DBManager();
}
return INSTANCE;
}
}
I dont really know what is causing the Nullpointer and why
Upvotes: 0
Views: 828
Reputation: 1470
Dropbox might seem to work for now, but the industry standard is to use a dedicated source control system like Git. You will probably run into issues that caused the formation of source control systems.
Upvotes: 1
Reputation: 7388
The exception output exactly states the line number:
Caused by: java.lang.NullPointerException
at application.DBManager.connect(DBManager.java:54)
Assuming the code in the question is the same as your production code, that Line 54 contains:
reportStatus.setMsg("Could not reach database.");
reportStatus
is probably not initialized, thus causing the NullPointerException
.
Upvotes: 1