Scott Vallery

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

Recent posts by Scott Vallery

Hi Tim H.,

Thanks for the pointer on the boilerplate templates. I've been working through Intellij since I initially started with Java. Your suggestion probably would have helped me tremendously - certainly in the future. I'm in so deep now, maybe there is still the possibility of refactoring. I've been working on this app for a year and half off and on, trying to learn everything in the process. So again, this will be very helpful.
2 years ago
Hi Tim M. and Tim H.,

Thanks for taking time to explain and providing an example. I will explore and consider this. My DB is pretty big with 8 tables and 3 Join tables, this would be cumbersome task to update since I need to learn a bit more.

Again, appreciate the advice and assistance!

UPDATE: Adding the add'l constructor suggested by Tim Moore worked! Thanks again.
2 years ago
Hi Tim,

Thanks for your response and help. I will need to admit, ORM and JPA had no meaning to me and I had to look these up before responding. I can't find these concepts in any Android Room implementation documentation online, instead, with different ORMs with the Hibernate being commonly referenced. Are you suggesting I use something different than Android Room for Android SQLite database interactions?
2 years ago
**Problem:** I've been learning Android Room and encountered a problem where a zero number (0) primary key ID exist. When I try to do an `insert` it returns a `UNIQUE` error pertaining to this zero ID existing. I suspect my handling of the constructor might be wrong the use of zero as a "new" insert ID; but it seems logical in a "get" List<> in a DAO, you would want to return the IDs of table entries?

**What I'm trying to do:** My understanding is that you have the option to incldue an ID field in your constructor. However, Android Developer's link about Entities (see below)  example has the ID included. So, I included the the ID field as a parameter so my entity would return an ID. So when I have an insert in my DAO, I pass a '0' which has never caused this issue in 100's of `insert cases ( the db has 8 tables) because all the tables will return the next value. However, now I have encountered this. I'm not sure the solution and what I should do at this point with 8 table Entity constructors with ID. Should I be passing zero to the constructor on new inserts?

https://developer.android.com/reference/androidx/room/Entity - the Android Developers example

**Example:** NoteID is the PK for this Notes.Class (this has getters and setters not included):

2 years ago
I was able to find some help by using the word "dynamically" instead of "programmatically." I discovered I did not to set LayoutParams for the TableRow itself (e.g., row.setLayoutParams()). Once I set these, I was able to set separate parameters for each cell item.

2 years ago
Hi Tim!

Thanks for the response, and a valid point and equally valid... why not? What if the filename length causes the same issue?
2 years ago
Problem:
When the TextView within a TableRow is populated with a user selected path and filename, if the length is too long, it forces the adjacent Views within the TableRow to disappear. The TableRows and Views within the TableLayout are created programmatically through Java, not through the activity layout XML, and I'm  having difficulty figuring out how to "fix the size" of one of these two column views within the TableLayout/TableRow, even if the path and filename run off the right edge of the TextView or switch to multi-line.

What I have tried:
I'm not totally unfamiliar with creating TableLayouts and related TableRows and Views through the activity layout xml. Doing so programmatically I'm not as familiar with. I have searched and posted to StackOverflow, performed some research with other user posted tutorials and posts, but nearly 100% deal with xml programming, not Java manipulation. I've tried inferring from those examples how to I might do so in the Java TableRow, Button and TextView objects, but I'm not having any success. I think I'm lacking an understanding between when to use the TableRow vs. Button and TextView layout parameters (e.g., width/height/match_parent/wrap_content). Anyhow, I'm stuck and can't seem to grasp the proper logic and hoping someone may be able to help me better understand how to achieve my intentions.

Background on functionality:
The Android activity layout (xml) creates what might be called a "TableLayout placeholder" within the activity that can be programmitically referenced and manipulated upon user button clicks. As a result, I have a singleton class that holds methods called when a user clicks either an "Add" button or "Delete" ( - ) button. When a user clicks the add button, it launches an Intent for selecting a file, based upon the user's selection, adds a new TableRow with a Delete Button view and a TextView with the path and filename. The Delete button removes the entire row if the user decides to remove it. The Add and Delete button functionality works, I just can't get the views to fit properly since I'm  having to learn how to adjust them through Java programmatically.

What I'm trying to do:
Using Java, I'm trying to "fix" the size of the Delete button (i.e., " - ") (Column 1) so it remains within the TableRow to the left, and allow the TextView to fill the remainder of the TableRow width, which in the end depends upon the type of phone and TableLayout width).

Below are a couple before and after images and code that I'm using to create the TableRows and related views (also see StackOverflowStackOverflow Post).

Activity Layout - TableLayout



The click of the "Add" button will launch this method's "else" statement to add a TableRow with 2 views (Button, TextView), which are two method calls following:



The methods called to create views for the delete Button and TextView:



2 years ago
Hello!

This issue seems kind of basic, and I have performed it successfully in the past. I'm not sure why it isn't working here in a different app. I hope someone may observe something I'm not seeing.

My Problem:
I cannot get Android Room to updated my app database. I am new to Android, but not Java, and I'm having trouble with Android Room not updating my application database. I'm not totally unfamiliar with Android Room, I performed a couple tutorials and I created a Note taking app using Android Room which adds, updates and deletes entries and it works - and I actually use it. I've in essence duplicated this method of updating in my app but I am not having any success.

What I have done:
I have stepped through the code step-by-step, and I can see the old and new data for updating. I also see it passed through Android Room code. The first thing I did was compare my coding to the Note app tutorial I created and in concept, my code appears correctly implemented. I've tried researching similar issues on the Internet but most of the time they are tutorials on how to implements updates using Android Room - not an issue related post. I did resort to posting to StackOverflow two weeks ago but have not received any suggestions, and probably because like me, everything looks good I posted. I decided I would try posting here since I learned lot about Java here and everyone has always been very knowledgeable and supportive.

StackOverflow: https://stackoverflow.com/questions/61209892/why-isnt-my-android-room-dao-not-updating-my-entity-i-e-table

A little background, the code and how it is intended to work:
The database is an ASSET and it is copied to an internal location under the app folder location (e.g. data/data/[com.app]/databases/myDatabase.db).Below is the code. This issue involves two tables, a Notes table and Questions table.

Notes table: Contains a Primary Key for each note corresponding to primary keys of 7 associated note related data.
Questions table: Contains a specific question that may be specific to one or multiple notes.

Initialization of the Notes data:  Pulling the Notes data associated to the current view. vNoteID is the note ID passed by an Intent




In this scenario, if the question data is different (which it is), update the current question:  Here the Questions Entity table is initialized and the current Questions object is pulled from the Questions table from the QuestionID in the Notes object above. The change is passed to the Questions Entity setQuestion method. The Questions object is then passed through the annotated @Update method in the related QuestionsDao.



The Questions Entity and Dao involved:

3 years ago
I feel stupid but solved my problem. I had my createFiles() method off during some testing on building out the opening of files. When I pushed the app to the phone I forgot to turn it back on.

Thanks Randy for your patience and help.
4 years ago
I did figure out how to get the phone to run in debug, however, accidentally... I simply unplugged the phone and plugged it back in and then I needed to approve the permission for debugging.

The Run, Debug, Logcat and Build tabs have no errors, and neither does the Event log. The issues are still the same.
4 years ago
I have not ever tried debugging with my phone so I took the time with your suggestions and tried. I started with "Run apps on a hardware device" on developer.android.com. When using Device Manager (Windows 10), I'm stuck on which driver to select, there are about 15-20. I used the wizard with searching sub folders and still received that the current driver was best. So I tried without since I kept getting the message that my current driver was the best. However, when I hook up the phone, it is an "unknown device" and click run the app fails to install and run. Any guidance would be helpful and then maybe I can find the real issue.

I've attached two images to clarify if needed.

https://developer.android.com/studio/run/device

4 years ago

My Problem:
I'm struggling to figure out why my app cannot open images (stored internal to the app in the Files directory created by the OS), but Android Studio and Emulator have no issue opening the images? When prompted to select an app (Gallery or Photo) on the phone, Gallery opens with an image of an explanation point, and selecting Photo results in a cursor hang on a blank screen.

The emulator build is Pixel version 9. The app is setup to the recommended minSdkVersion of 28, and compiled and targeted to 29. The phone is a Galaxy A10e which is also Android version 9.

What I have done:
I've worked with this code a lot since I'm 4-6 months new to Android development. I'm using the following Intentdriven code and have used a hard coded mime type (e.g. "image/jpeg"), a MimeTypeMap class in case that worked better, and also eliminated the mime type designation altogether. In all 3 cases, the app opened the images successfully in Android studio, but all failed when installed to the phone.

I'm not sure where to go from here. It is quite possible I'm missing a simple step or issue. If there is more that I can add to help me solve this issue I will be happy to provide it. I have posted this issue at StackOverflow (see link below), but I forgot about Java Ranch and Code Ranch and have had friendly, successful help here in the past with other Java projects. I tried to find the posting rules as to whether I was allowed to post since I did to StackOverflow, so I apologize if I broke any rules.




Posted question here also:
https://stackoverflow.com/questions/60767354/why-do-images-open-with-my-app-in-android-studio-but-when-installed-on-my-phone

4 years ago

Campbell Ritchie wrote:FXML? Why didn't you say so earlier? Please give us the full details, because the correct answer might be totally different.



Hi Campbell!

I didn't know earlier, I just happen to notice stepping through it was occurring there. However, I did figure out what was happening and was able to fix it.

The long delay was caused by the ConnectionModel class initialization and call to the DBConnection class attempt to connect to a SQLite database file. In other words, when the FXMLLoader calls to the FXML and loads, and the associated ResearchController class is called. The ResearchController class declares the ConnectionModel and becomes a variable and intializes, calls and connects to the SQLite database file. Since SQLite is built upon the use of a file and it was missing, the ConnectionModel was creating the blank file. This was all occurring before the initialize() method of the ResearchController class. Since my check was within this initialize() method, the file was being created before this method call and my files.exists() check.
4 years ago
Sorry, accidentally added this to an earlier post....  Here is what I found.

When the FXMLLoader is called, this is when the file is being created... and before the check provided as a suggestion above located in the FXML's controller class.

Here is what happens:
If I add a break point at this FXMLLoader.load call and a break point on the first line of the Controller for the FXML... there is a 5-10 second lull when the file is created.  I don't know how to see what is happening in that window.

Any thoughts?

4 years ago
Ok, I've narrowed it down to being created before, but I don't know where, or whether it is somehow stored in memory.
4 years ago