Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: importing java librarys

  1. #1
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default importing java librarys

    hi im am trying to use apache Commons IO 2.4 in an app im building however im having trouble importing it to my android project
    Right-click libs and choose Import -> General -> File System, 
    Browse in the filesystem to find the library's parent directory
    then check the relevant JAR in the right pane. 
    Right-click on project, choose Build Path -> Configure Build Path, 
    then click the Libraries tab,
    navigate to my new JAR in the libs directory and add it.
    is how im importing it into eclipse which i think is right however i am still unable to use the classes whitin the package does anyone know why these errors are happening?
    i am allso trying to use Package javax.sound.sampled which is a native part of java sdk since version 6 but am unable to do so why? thanks


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: importing java librarys

    Quote Originally Posted by bean
    i am allso trying to use Package javax.sound.sampled which is a native part of java sdk since version 6 but am unable to do so why? thanks"
    Strictly speaking Android isn't Java. It does use a partial subset of J2SE and if you check the Packages list you will find javax.sound isn't included. See Managing Audio for another option.
    Computers are fascinating machines, but they're mostly a reflection of the people using them.
    -- Jeff Atwood

  3. #3
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: importing java librarys

    aaaargh! thanks for reply was already looking at that option but managing audio api to be blunt "sucks" it seems to record audio you must save it to sd card and then play it from there which is a terible way to deal with audio and in my case i would imagine it would create countless deadlock situations it does not seem possible to save it to a byte[]

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: importing java librarys

    Have you read up on MediaPlayer and SoundPool. They are really excellent classes that will suite 99.9% of problems.

    Quote Originally Posted by bean
    it does not seem possible to save it to a byte[]
    I suppose if you *really* wanted to it would be possible but I can think of dozens of reasons why it would be a bad idea. One of the most painful and hard to sink in lessons I've come to learn with Android is that you shouldn't fight against it. Chances are there is a very good reason things are done the way they are.

    Quote Originally Posted by bean"
    and in my case i would imagine it would create countless deadlock situations
    Prove it..
    Computers are fascinating machines, but they're mostly a reflection of the people using them.
    -- Jeff Atwood

  5. #5
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: importing java librarys

    thanks i had a brief look at them but futher study is needed however i tried a little hack of importing rt.jar from my java sdk which allowed me to import the classes i needed from java and got no errors in code the app ran fine however crashed when i tried to launch the activity any ideas on why this happened if the classes where there and thanks for replys

  6. #6
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: importing java librarys

    rt.jar contains the Java runtime tools (there is no reason to mess around with this jar unless you are doing something funky like writing a bytecode interpreter). As I said before, Android isn't Java in the strictest sense. In fact it doesn't even use the JRE to execute java bytecode, it uses the Davlik VM to execute DEX files. It's an entirely different architecture and they are not compatible. The crash you are experiencing is un-resolvable.
    Computers are fascinating machines, but they're mostly a reflection of the people using them.
    -- Jeff Atwood

  7. The Following User Says Thank You to ChristopherLowe For This Useful Post:

    bean (August 9th, 2014)

  8. #7
    Member
    Join Date
    Apr 2013
    Posts
    83
    Thanks
    7
    Thanked 3 Times in 3 Posts

    Default Re: importing java librarys

    thanks i found audiorecorder api and it seems to be what im looking for as opposed to mediaplayer as audioplayer can be fed into an array thanks for replys and helping me further get to grips with this im very noob to android

  9. #8
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: importing java librarys

    Just a parting word of advice; use the Android toolset for Android problems where possible. The MediaPlayer may seem complex at first glance but it was designed for Android from the ground up and it's highly unlikely this AudioRecorder API is superior in any way. Chances are you will be fighting with dependencies, codecs, OutOfMemory exceptions and general instability before the day is out.

    Whenever I encounter a problem that isn't handled by the Android toolset I do whatever I can to prevent entering into an escalation of complexity spiral. First I'll thoroughly explore the SDK incase I've missed something. Then I will post on StackOverflow with an MCE and list of things I've tried. If there legitimately isn't an solution I will make a feature request on the Android google group. Then I'll sit on it for a few days and have a chat with colleges and programmer friends in the hope an alternative solution occurs to me. As a last resort I'll bite the bullet and roll out my own solution.

    You'll notice the one thing missing here is hacking in a solution from a different framework that I happen to know about.

    My point is that just because reading a sound file as a byte[] worked in vanilla Java doesn't mean it will work on Android. Writing it to SD on an asynch task then reading the file as an input stream achieves the exact same thing without going down the rabbit hole.
    Computers are fascinating machines, but they're mostly a reflection of the people using them.
    -- Jeff Atwood

Similar Threads

  1. importing EXcel Data into ql database through java
    By akchatteree in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 3rd, 2014, 09:42 AM
  2. JAVA CODE FOR IMPORTING XLS FILE INTO MYSQL
    By abhi1402 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 8th, 2013, 07:19 AM
  3. JAVA CODE FOR IMPORTING XLS FILE INTO MYSQL
    By abhi1402 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 7th, 2013, 04:03 AM
  4. Java importing to JFrame get pixel color
    By chivas12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 1st, 2013, 08:31 PM
  5. Necessity of importing java.awt.event.*
    By Dracone Cordis in forum Java Theory & Questions
    Replies: 4
    Last Post: January 8th, 2012, 11:50 AM