Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:09:15+00:00 2026-05-31T13:09:15+00:00

please can anyone tell me the error ! i get error in the line

  • 0

please can anyone tell me the error ! i get error in the line
btmp.compress(Bitmap.CompressFormat.JPEG, 80, baos);

everything works fine for an PNG image taken from the drawable folder but when i try to access the card image or any jpeg it gives error in compress…

    public class img2byte extends Activity {

TextView tv;
Bitmap btmp = null;
ByteArrayOutputStream baos = null;
byte[] bytes;
File file=null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv = (TextView) findViewById(R.id.textView1);

    file=new File(Environment.getExternalStorageDirectory()+"/image.jpeg");
    Uri abc =Uri.fromFile(file);
    tv.setText(abc.toString()+"\n");

    Log.i("da","Got Uri");

    try {
        Log.i("da","before btmp");
        btmp = Media.getBitmap(getContentResolver(),abc);
    } catch (FileNotFoundException e) {
        tv.setText("file not found");
        System.out.println("sjadhad");
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    baos = new ByteArrayOutputStream();
    btmp.compress(Bitmap.CompressFormat.JPEG, 80, baos);
    Log.i("da","compressed");

    bytes = baos.toByteArray();
    tv.append(""+bytes.length+"\n");
    tv.append(baos.toString());
    for(int i=0; i<bytes.length; i++) 
        tv.append(""+bytes[i]);
    }

}

Logcat :

03-18 10:46:18.699: ERROR/AndroidRuntime(20379): FATAL EXCEPTION: main
03-18 10:46:18.699: ERROR/AndroidRuntime(20379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dhiraj.img2btye/com.dhiraj.img2btye.img2byte}: java.lang.NullPointerException
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.os.Looper.loop(Looper.java:143)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread.main(ActivityThread.java:4263)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at java.lang.reflect.Method.invokeNative(Native Method)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at java.lang.reflect.Method.invoke(Method.java:507)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at dalvik.system.NativeStart.main(Native Method)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379): Caused by: java.lang.NullPointerException
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at com.dhiraj.img2btye.img2byte.onCreate(img2byte.java:49)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
03-18 10:46:18.699: ERROR/AndroidRuntime(20379):     ... 11 more

I edited my code as follows :

File file = new File(Environment.getExternalStorageDirectory(),"/image.jpeg");
    Log.i("da", "Got file");
    InputStream in = null;
    OutputStream out=null;
    try {
        in = new BufferedInputStream(new FileInputStream(file));
    } catch (FileNotFoundException e) {     

        Log.i("da", "file not found");
    }

but i get FileNotFoundException. i have the file image.jpeg in my sdcard… any suggestions !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:09:16+00:00Added an answer on May 31, 2026 at 1:09 pm

    If all you need is to get the file’s content as an input stream, why go round the bush?

    File file = new File(Environment.getExternalStorageDirectory(), "image.jpeg");
    InputStream in = null;
    try {
        in = new BufferedInputStream(new FileInputStream(file));
        // Read from the InputStream and send over BT
    } finally {
        if (in != null) {
            in.close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone please tell me why I get the following error when I try
Can anyone please tell why this error? I have included everything ( all header,
Please can anyone tell me what the error is in the following piece of
Please Anyone can tell me why i got this kind of error: ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error
I need to update jquery1.3.2 to jquery1.4 (in Asp.net MVC). Please can anyone tell
Can anyone please tell me if Certifying Authorities (CAs) are allowed to make modifications
Can anyone please tell what is change request management tool and what is involved
Can anyone please tell me why compiling a C# application with a .cs file
Can anyone please tell me when should I use MessageContracts and when should I
Can anyone please tell me how do I make this script run in IE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.