• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Application Not Opening

 
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there, i am a complete amateur as far as android application development goes but i have experience with java.I managed to build a flashlight application but when i run it it does not open and i do not know why that is,below i will post some of my scripts .java and .xml and i hope you can help figure it out.

NOTE : Android Studio was used

AndroidManifest.xml



MainActivity.java



MainActivity.xml



Hope you can help me figure this one out!
 
Bartender
Posts: 598
26
Oracle Notepad Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm no expert. Still learning myself!

When using Android Studio, though, you can see the logs. Also, using Log.d() to specify a tag, and then filter on that tag to see what is going on. You can check if you are making it to onCreate(), at the very least.
 
stelios papamichael
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Tkatch wrote:I'm no expert. Still learning myself!

When using Android Studio, though, you can see the logs. Also, using Log.d() to specify a tag, and then filter on that tag to see what is going on. You can check if you are making it to onCreate(), at the very least.



Ok, i fixed the issue that was causing the app to close but i came up to another problem that seems to crash the app again.Please check the post again since i will update the code files MainActivity.xml and MainActivity.java if you are willing to help me again ! Thanks in advance!
 
stelios papamichael
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NVM, i cannot edit the post so here are the updated files :

.xml



.java



As you can see,i decided to play around with the images visibility instead of the resource of the image as that was causing my app to crash previously.But for some weird reason this setup does not seem to work even though it looks fine to me.I click on the off button when i launch the app and it crashes and the log files don't tell me much.Any ideas?Have i done something wrong in my code in general or in the order that my code is layed out?
 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


When using Android Studio, though, you can see the logs. Also, using Log.d() to specify a tag, and then filter on that tag to see what is going on. You can check if you are making it to onCreate(), at the very least.



This is good advice. Whenever an app crashes, there's a lot of important information in the log, foremost the stack trace that tells you what happened, and in which line of the code. Post the stack trace here.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why aren't you using a ToggleButton?
That would get rid of the whole logic around visible/invisible and the isOn flag.
You could then also use onCheckedChange instead of onClick.
 
stelios papamichael
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Why aren't you using a ToggleButton?
That would get rid of the whole logic around visible/invisible and the isOn flag.
You could then also use onCheckedChange instead of onClick.



Any ideas on what i should change in my app to use a tohhlebutton or switch without re-writting the whole app?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of having two ImageButtons you'd have a ToggleButton.
Instead of using onClick you'd use the onCheckChanged (I think that's the method) which gives you the View (ie ToggleButton) and the new value (on or off).

You can remove the isOn flag.
Inside the listener (now onChange) you'd not worry about the visible/invisible stuff (so throw that away) you'd just worry about the flash bit:

Note that that is not copy/paste code!
 
stelios papamichael
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Instead of having two ImageButtons you'd have a ToggleButton.
Instead of using onClick you'd use the onCheckChanged (I think that's the method) which gives you the View (ie ToggleButton) and the new value (on or off).

You can remove the isOn flag.
Inside the listener (now onChange) you'd not worry about the visible/invisible stuff (so throw that away) you'd just worry about the flash bit:

Note that that is not copy/paste code!



I read the documentation, show some other examples and tutorials on youtube about togglebuttons and switches but didn't find out if you can use images for this.As you saw i do wanna use my custom images and not just a pre-made toggle switch.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The accepted answer here pretty much covers it:
http://stackoverflow.com/questions/18598255/android-create-a-toggle-button-with-image-and-no-text

You're essentially creating a bespoke style for your toggles.
To me that's what you are trying to do, and shifting the heavy lifting into the XML definition of the style is preferable to carving out some code that is, basically, what the ToggleButton already does.
 
stelios papamichael
Ranch Hand
Posts: 93
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only errors i get when running my app are these two but nowhere i could find a solution :

09-09 20:42:24.101 10348-10348/comspdesign.wixsite.httpsteliospapamichael0.flashlight E/Camera-JNI: android_hardware_Camera_native_setup Error: -1
09-09 20:42:24.101 10348-10348/comspdesign.wixsite.httpsteliospapamichael0.flashlight E/Camera: Camera new cameraInitNormal:-1

Any ideas?I tried a ton of things that i saw on youtube but could not find anything on google!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic