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

  • Home
  • SEARCH
  • 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 8289919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:38:26+00:00 2026-06-08T12:38:26+00:00

import android.os.Parcel; import android.os.Parcelable; public class MClass implements Parcelable { private byte[] _byte; public

  • 0
import android.os.Parcel;
import android.os.Parcelable;

public class MClass implements Parcelable {
    private byte[] _byte;

    public MClass() {
    }

    public MClass(Parcel in) {
        readFromParcel(in);
    }


    public byte[] get_byte() {
        return _byte;
    }

    public void set_byte(byte[] _byte) {
        this._byte = _byte;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeByteArray(_byte);
    }

    public void readFromParcel(Parcel in) {
        in.readByteArray(_byte); //LOE - Line Of Exception
    }

    public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
        public MClass createFromParcel(Parcel in) {
            return new MClass(in);
        }

        public MClass[] newArray(int size) {
            return new MClass[size];
        }
    };

}

Whenever I am going to retrieve the bytes in my following array it is returning exception of NullPointerException. Can any one say what is the problem? What I am trying to do is to transfer a downloaded image bytes from one activity to another.

  • 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-06-08T12:38:28+00:00Added an answer on June 8, 2026 at 12:38 pm

    You never initialize the _byte array upon reading the parcel, therefore it is null.

    What I’d do is, when you write your parcel, store the length of the byte array followed by the actual byte array. When you read the parcel, first read the length and initialize your _byte array to a new array of that size, then read in the byte array.


    Code moved from comment

    In write…

    dest.writeInt(_byte.length); 
    dest.writeByteArray(_byte); 
    

    and in read…

    _byte = new byte[in.readInt()]; 
    in.readByteArray(_byte);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes : import android.cla; public class CW { public static void
import android.content.Context; import android.content.SharedPreferences; import android.net.Uri; public class LoadSettings { public static void LoadMySettings
My source code is: import android.content.Context; import android.hardware.SensorManager; public class ShakeEvent implements SensorEventListener {
import android.content.Intent; import android.net.*; public class ignitionClass { Intent dialI = new Intent(Intent.ACTION_CALL, Uri.parse(tel:610-970-1218));
import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; import android.os.Bundle; public class Map2Activity extends MapActivity { /** Called
Code: import com.independentsoft.exchange.Service; import android.app.Activity; import android.os.Bundle; public class ContactsToExchangeActivity extends Activity { @Override
import java.lang.ref.SoftReference; import java.util.HashMap; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.Message; public class AsyncImageLoader {
Hey Everyone, import android.widget.Button; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.webpage); but_action =
I got this class: import android.content.Context; import android.media.MediaScannerConnection; import android.net.Uri; import android.util.Log; public class
package com.example.android.home; import android.app.Activity; import android.os.Bundle; import android.widget.*; import android.view.*; public class HomeActivity extends

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.