This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Android and the fly likes How do I use a class I found? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "How do I use a class I found?" Watch "How do I use a class I found?" New topic
Author

How do I use a class I found?

Sam Kostler
Greenhorn

Joined: Jan 20, 2013
Posts: 4
So, I'm merely a hobbyist, I write applications because I need to use them. For the most part I've been successful at successfully completing projects with the languages I've poked around with, but for some reason Java is really not connecting with me.

I found this code example:

http://stackoverflow.com/questions/6959930/android-need-to-record-mic-input

I get it. I understand what's happening there. I have no idea, however, how I go about using it in a project. I feel like a moron for not being able to figure out what ought to be the simplest part of this process. I've worked through tutorials, I have other applications running, but I just cannot suss out where to put this or how to access it. Perhaps it's just one of those days and tomorrow it'll be crystal clear, but right now I'm deeply frustrated and could really use just a little help on this.

Thanks!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

For that particular code you need to look at some of the clues. First - the class is labeled as private - which means you are meant to put it inside some other class, probably an Activity. Second, it extends Thread (which is a bad idea) and so you generally execute a thread by calling the Thread.start method. You do not see the start() method in the posted code because it exists in the Thread class, so you have to know how to use the Thread object, or look up the API for it. You would probably call the start() method from a button click or something - that part isn't clear, but would make sense. So if I were to use that class* I would do something like this:


* If I were to use it I would probably make it not extend Thread, but that is for another discussion...


Steve
Sam Kostler
Greenhorn

Joined: Jan 20, 2013
Posts: 4
Thanks very much!

I'll give that a shot and see if I can't get it working.

I hate to bug you, but everything I've done with programming up until this has involved functions. Would you mind explaining, or pointing me to an explanation of what a class is and how it differs from a function? Also, what exactly is an activity and why do class blocks of code *have* to be in separate ones? Lastly, am I totally missing something about Java and Javascript? When I found Android used Java I was relieved since I'm reasonably comfortable with Javascript (well, really with Apps Script, but it's based on Javascript), but for the life of me I can't figure out the similarities.

Thanks again!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Sam Kostler wrote:Lastly, am I totally missing something about Java and Javascript?

The main thing you need to know is that they are completely unrelated

Sam Kostler wrote:When I found Android used Java I was relieved since I'm reasonably comfortable with Javascript

I'm afraid that won't help. If you were reasonably comfortable with Java, you'd be better off, but there would still be quite a bit to learn.

Joanne
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3432
    
  12
Sam Kostler wrote:Would you mind explaining, or pointing me to an explanation of what a class is and how it differs from a function?

This is probably a good place to start.
Sam Kostler
Greenhorn

Joined: Jan 20, 2013
Posts: 4
Thanks, I still haven't gotten it quite working, but I think I just need to step back and go through some tutorials again so I can better understand the grammar of the language (I'm not sure if that's the right word, but it seems like it fits).

I think I expected a lot more of what I knew to translate between languages and I didn't spend enough time on the basics.

Any recommendations for tutorial series' which spend a lot of time on the structure of the language as opposed to logic, variables, and conditional statements?

Thanks again!
 
Consider Paul's rocket mass heater.
 
subject: How do I use a class I found?
 
Similar Threads
Strip Out XML From SOAP to Validate
Edit masks in text fields
Should I spend time to learn Flex, currently as a Java/J2EE developer
Applet that lets you draw shapes, custom component and action
Using Java From ASP