Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!

Scott Vallery

Ranch Hand
+ Follow
since Feb 11, 2018
Scott likes ...
IntelliJ IDE Eclipse IDE Java
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

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:

4 weeks 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.
2 months 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.
2 months 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

2 months 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

2 months 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.
10 months 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?

10 months 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.
10 months ago

if( new File(file).exists() )



I tried this before but did try it again, the file still gets created.

There must be something else going on because I agree that this should work... I would suspect it too.
10 months ago
My Problem:
I must really be stupid or have a severe brain strain but I cannot seem to check if a file exists without the check creating a bogus file. Every one of these examples below creates the non-existent file (a bogus one) that does not have the expected data (of course) and crashes the application, when it simply should check.

Isn't there simply a check to see if a file exists without it needing to be created?

What I'm trying to do:
Simply check if a file exists without the checking method creating it.

Below are all the suggestions for checking, but all of them create the file... which I do not want. I simply need the code to check.

10 months ago
Hi Norm!

Thanks for the suggestion and it worked! I did suspect I may need to try your method but just hadn't. Below is the solution; HOWEVER, it only works when executing the executable jar vs during development, which is perfectly fine. That's how it needs to work.

I initialized JarFile and passed and called the getJarEntry directly within the SimpleDateFormat parsing method. The JOptionPane is simply used to validate/debug the result of the getTime() method.

Thanks again!!

10 months ago
My Problem:
I'm trying to check an existing desktop file modification date/time against a copy of the same filename within my executable jar. I'm able to check a jar file modification date/time within my project structure against the desktop location of the same file during development, but it will not work after the executable (jar) is created and I try it in real-time.

What I'm trying to do:
Below is the code to check the LastModifiedDate(). A jarPath is retrieved during each launch of the jar. During the initial install, this jarPath is/was used to extract all files within the jar to a application specific location and then launched. Thereafter, each launching of the jar validates whether an install exists and the application simply launches. Now, if there are minor updates, I would rather validate desktop modification date/time stamps against the same files in the jar, and if there is an update, push those to the user's desktop. The method below is a boolean method I'm using to validate the desktop modification date against the same file within jar to determine whether to update or not. Right now, this works during development testing, but as soon as I create the executable jar and try it, the jar file mod date returns the DEC 31, 1969 date and not the actual mod date... indicating it cannot call it. The JOptionPane is just my debugging popup to validate variables in the method when launching the executable jar.

10 months ago
g tsuji and Tim!

Cool thanks for the input! I ended up using the Base64 wrapper and it worked great as well. I was running into an issue with byte[] > XML String > byte[] and Base64 seemed to solve my issue after this solution.

I'm good with this being resolved if you concur! Thanks!!
I resolved my own issue!

After further research the solution was the use of Base64.  --  Base64.getEncoder().encodeToString(bytes)

Base64 during the XML creation (export) process:


Base64 during the XML reading (import) process to create the file: -- Base64.getDecoder().decode(childList.item(cl).getTextContent().getBytes())

11 months ago
I think this is the correct place to post for an XML file conversion stream??

My Problem:
The escaping of file bytes and converting to string using the Apache StringEscapeUtils for XML file transmission appears to be corrupting the file bytes. The StringEscapeUtils is necessary to allow the byte data to be embedded in the XML and prevent parsing issues.

What I have done:
To be sure, I've isolated the issue to this recommended StringEscapeUtils process. The following line of code casts an object array of bytes back to bytes[]. I have no issue thereafter this code creating and opening any file (e.g jpg, xlsx, docx, png, txt... etc) using this byte array from this line.

If I take these file bytes and escape and unescape them during the import export processing of the XML doc it somehow corrupts my files.

Code escaping the byte[] data to string and creating the <filedata> node:

Code unescaping the <filedata> tag data:

Any thoughts on what I may be missing? Maybe I need to escape the bytes differently?

Thanks!

11 months ago