Scott Vallery

Greenhorn
+ Follow
since Feb 11, 2018
Scott likes ...
Eclipse IDE IntelliJ IDE Java
Ohio
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
2
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Scott Vallery

Ok, I guess I solved my own problem. I apologize for wasting anyone's time. However, maybe this will solve someone else's problem in the future.

I move my private variable to a local method variable and that seemed to work.



4 days ago
I'm struggling on how to update (or .add) to an existing ObservableList (see code below) that populates a ChoiceBox. I didn't have this issue before but now it is failing -- not sure what I did. I've done some reading and read the Oracle Doc for ObservableList and some other forum posts, but some of it seems too complicated for a simple update. So I was wondering if I needed to simply create the list (i.e. sources) as a local variable within the initializeSourceBox so it is created new every time and pass it back to my ChoiceBox?

What I'm trying to do:
The application provides the user, through a JavaFX ChoiceBox, a list of sources by title and author(s). The user can choose a source from this 'existing' list or add a new source (title and author(s)) through separate TextFields, which will then be updated to database tables. After this new source has been added to the DB, the next time the user attempts to select from the source ChoiceBox, the 'OnAction' event associated to this ChoiceBox will populate with all the available sources which includes the new one added. This worked before but now it doesn't unless the application is closed and restarted.

My Problem:
The ObservableList<String> will not allow a new source to be added unless the application is stopped and restarted.

Other details:
A Search Class queries data from Source and Author tables in the form of a HashMap associated by a source ID (key). The HashMap has an ArrayList of the details needed passed back to a HashMap in the code below. The details needed are concatenated into a string that is added to the ObservableList<String> 'source' used to populate the ChoiceBox. BTW, the Search class method CaptureSources is used for other information in other parts of the application, so that is why it is not directly implemented into the ChoiceBox set items.

Declarations:

4 days ago
Hi Everyone!

Daniel -- sorry, I wasn't as clear as I should have been, but if a user doesn't know a source exists, they may add the authors in a different order that listed on the database retrieval. However, I see what you are saying... and I could probably just us the 'sorted()' method on each ObservableArrayList... duh!. Like I said, I can be thick.

Right now the goal is to get something working then begin to refactor to be more efficient. I feel (obviously ) this application can be far more efficient and understandable. I'm just not experienced enough and naive at the present time.

Anyhow, this is working at present. I continued with the overriding of the "toString()" and applied part of Carey's suggestion to convert any 'null' value as a "". My Convert method may be in efficient, as I mentioned before, the null and "" and " " are what I'm trying to handle.




Author Class:

5 days ago
Oh... and the table entries may be in any order, which I can handle with some looping. I forgot to mention that caveat.
5 days ago
Daniel, Carey, Campbell!

These are some good thoughts. Let me try these. As a Greenhorn, I need to run them through my thick head a couple times to understand what is happening with each. I did construct the override of "toString" but it has to be too precise. The difficult piece for me every time is dealing with null vs "". I did create an Object compare method to help with this in another section of the code, which maybe I can incorporate.

Thanks! I should have something soon!
5 days ago
Hi Daniel and Campbell!

Good points and I totally agree with you both - So I appreciate this site and your patience and efforts.
This is the first application in Java for me and it is further compounded by needing JavaFX and Databases - and I've had 1 weeks worth of high-level training and hit-miss tutorials. -- Sorry for the wrong forum.

After continuing to research, I understand now why the object comparison will always return false. So I was attempting to build out an override of 'equals' as suggested but I was failing miserably. So I think the 'toString' override is a good suggestion too and I should try. I will refactor the naming the 'Authors' to Author.

I will reply with my success or failure! Thanks! It is greatly appreciated.
6 days ago
I wasn't sure if this should be in the Beginning Java - though I'm a greenhorn

The Question:
How do I compare two ObservableList?

What I'm trying to do:
Since there can be many sources (e.g. book, video, magazine, etc) )with the same exact title in the database but possibly different authors. I'm attempting to compare a list of Authors for each existing source found in the database to the list of authors entered by a user. So this is my test code for planning and constructing this method in "DoSourceAuthorsExst()" which will most likely become a boolean method. The 'sourceAuthors' will be the result of retrieving all the authors of an existing source as Author objects and compare that list to the user's list of author objects, which the authors table is based.

My Problem:
The two ObservableList<Authors> objects are identical. I literally copied one and pasted it -- renaming the second as 'sourceAuthors'. It seems no matter what I do, the result is always false. I feel I'm overlooking something simple, I'm just too thick to see it. I could use a second or more set of eyes to see it.



the Authors Class:
6 days ago
Hey, I'm all about simple, efficient and clearly understood! I like your signature line "An IDE is no substitute for an Intelligent Developer." I just need to get there. I'm leaning on Intellij tohelp me find efficiencies at the moment. Your suggestion is good and I agree (for what that is worth) that adding back in the back slashes. However, I did not pickup on the sample code for the file directory and file name you provided. I like that.

Everyone is so helpful on this site. I was attracted to the idea new Java users could learn here with "no question too simple", instead of "why are you doing that stupid".

Thanks again Tim!
1 week ago
Hi Paul and Tim!
Based upon your comments, you may or may not approve of this approach, but here is what I have done and provided the code below. It took all day to research how and to create it, but I built an Install Class to verify and/or install the database. Since the JAR file in essence is like a ZIP file, the main class of my app (i.e ResearchApp) will implement the Install class and then verify or install the database to the users home path, validating and managing folder permissions. So far, it has worked on a couple user systems but I'm sure I may run into an issue being new to java and attempting at my best to manage all possible exceptions.

In essence, the first thing the Install will do is capture path where the JAR resides and then call to the users home path and concatenate an application folder, then check if the folder path and file exists. If not, it will iterate through the JAR to find the DB then try to confirm and or manage folder/file permissions if it fails to create. This database will come with some initial data samples. If successful, the later attempts to skip the install if the Install object class validates successfully. Thereafter, database connections are established success or failure.

I'm certainly still open to thoughts or suggestions on this attempt.

ResearchApp (main) call:


Install Class:

1 week ago
Being a Java newbee, I  missed it. I struggled with this for a few days before finding what I did and thought I would post so the next newbee wouldn't struggle as long. LOL! There are actually 2. The second does the same as the first except you also have the option of restricting the user to options in an array while providing a default. There is also more control, offering a Title and Icon if preferred.

1) showInputDialog​(Object message, Object initialSelectionValue)

2) showInputDialog​(Component parentComponent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
1 week ago
I'm really struggling to with my Intellij jar (executable). I'm ready to hand it out for some friendly  user testing but Intellij won't handle the embedded SQLite db. So I was hoping someone would have a suggestion or solution.

The embeded DB is called research.db. Here are my details:

Code referencing the DB:

Where it is located:
src > research.db

Problem:
I cannot get the Jar to run because it cannot access the DB. What I thought I could do was create a "sqlite" folder under the src folder and Intellij would embed (literally) the DB within the JAR. I don't think that is possible  now. So I moved it where it was previously, back within the src folder.

What I've done:
I've been on a number of sites each with similar steps using Intellij (see attached image). I reached out to Intellij Community support then eventually was asked to enter a ticket, and they found the jar works but the database is the issue causing it not to launch.

I've never, ever, created an installer in my short coding career, but I don't know if that is what needs to happen and edit the SQLConn (above code) in my application code. I did something similar but smaller than this in NetBeans with a DB and had no issue, but the DB was outside the JAR and had to be within the same folder. So I'm not sure what is different about Intellij.

I'm open to any suggestion or pointer in the right direction.

Thanks as always!

1 week ago
I wasn't sure where to post this or if there was a helps forum, but having asked many questions here, I thought I would contribute a solution or helper that I found valuable and would like to share!

I was surprised in searching myself for an answer on this subject how difficult it was to find a clear solution or coded around it, making it far more complicated than it needs to be. Even the Oracle docs were hard to follow. In Intellij, you only see a couple overloaded methods instead of the full range of options unless keep typing commas, and so naive people like me think there are not any remaining overloaded methods. By the time you get to the Icon and button parameters you thin you are at the end... Not so here! These default parameters fall after the icon and appear as the last two parameters.

The first of the two defaults I have marked bold, 'null', is a very cool parameter allowing you to enter an array of options (String[]) of 'selection values'.


A list with with a default picked
    JOptionPane.showInputDialog(null, "What primary color is your favorite?", "Pick a color", JOptionPane.PLAIN_MESSAGE, null, ans, ans[0])
or...
No list (null) and default string
    JOptionPane.showInputDialog(null, "What primary color is your favorite?", "Pick a color", JOptionPane.PLAIN_MESSAGE, null, null, "Red")

1 week ago
I was able to get it working but I think it is inefficient. In essence, I had to capture the values into a separate array and then loop through that array and to pass the values into the method. I would think I could just do those simultaneously. But, I'm happy, it works.

           while (resultSet.next()){
               temp.add(resultSet.getInt(table + "ID"));
           }
           temp.forEach((Integer i) -> CaptureSearchNoteIDs(table, i));

The Java code below will only return a single result when I know there are 2 or more and I'm not sure why?

What I've done:
Typically, before I build the SELECT query in the Java code, I will test it in SQLite, which is embedded in this application. If it works, I convert it to code and usually no issue.

Problem:
Below are the original SQLite query and the SELECT query concatenated by Java and they are identical. So, I'm not sure why my result set is only returning, in this case, one of two possible results? I'm uncertain if the problem lies elsewhere?

What should happen:
After the query, results are dumped into the resultSet, then for each result (while), the value is passed to a method for further processing.

SELECT SourceID FROM Source WHERE Title LIKE '%Chinese%' - SQLite

SELECT SourceID FROM Source WHERE Title LIKE '%Chinese%' - Java code query string