I've made a simple dictionary using JavaFX. I've used a SQLite Database and some pictures into my application. I exported the application as a runnable JAR file using e(fx) Eclipse. I followed the steps described here - https://wiki.eclipse.org/Efxclipse/Tutorials/Tutorial1.
After exporting I opened the .JAR file. It opened successfully but wasn't working properly. It wasn't showing the results from the database and images.
When I ran the application into Eclipse workspace before building & exporting, it worked fine.
Where is the problem? How do I fix it?
Here is the code for the Controller Class function:
package imran.jfx.application;
import java.io.File;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
public class Application_Controler implements Initializable{
@FXML
private HBox hBox;
@FXML
private Label searchLabel;
@FXML
private TextField searchWord;
@FXML
private VBox vBox;
@FXML
private Text BanglaMeaning;
@FXML
private TextArea bnMeaningTxt;
@FXML
private Text bAcaMeaning;
@FXML
private ScrollPane bAcaMeaningImg;
@FXML
private Label footerLabel;
ResultSet result;
PreparedStatement doQuery;
Connection conn;
String query;
@Override
public void initialize(URL location, ResourceBundle resources) {
try
{
Class.forName("org.sqlite.JDBC");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
String url="jdbc:sqlite:src/imran/ankurdb/meaning/bn_words.db";
try
{
conn = DriverManager.getConnection(url);
}
catch (SQLException e) {
e.printStackTrace();
}
}
@FXML
void showMeaning(ActionEvent event) throws Exception {
bnMeaningTxt.clear();
String text=searchWord.getText();
query = "select en_word,bn_word from words where en_word='"+text+"'";
doQuery = conn.prepareStatement(query);
result = doQuery.executeQuery();
int i=0;
while (result.next())
{
if(i==0)
{
bnMeaningTxt.appendText(result.getString(1) + "\t\t" + result.getString(2));
i++;
}
else
bnMeaningTxt.appendText(" , "+result.getString(2));
}
File file = new File("src/imran/bnacademy/meaning/"+text);
Image image = new Image(file.toURI().toString());
bAcaMeaningImg.setContent(new ImageView(image));
}
}
Fileto load images which are present inside your jar. You need to use the classloader to load them instead. - ItachiUchiha