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 8127295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:28:31+00:00 2026-06-06T07:28:31+00:00

I have two helper methods inside a custom View which are called by their

  • 0

I have two helper methods inside a custom View which are called by their Fragment:

public Bundle returnInstanceState() {
        Bundle state = new Bundle();
        state.putSerializable("colorData", colorData);
        return state;
}

public void loadInstanceState(Bundle savedInstanceState) {
    if(savedInstanceState.getSerializable("colorData") != null)
            colorData = (int[][]) savedInstanceState.getSerializable("colorData");
}

The lifecycle of colordata:

private int[][] colorData;

protected void onSizeChanged (int w, int h, int oldw, int oldh) 
{
    width = w;
    height = h;
    screen = new int[width*height];
    cellSize = 0;
    if(firstLoad && h!= 0 && w!=0)
    {

    if(nWidth>nHeight)
        colorData = new int[nWidth/(nHeight/170 - 1) + 1][170];
    else
            colorData = new int[nHeight/(nWidth/170 - 1) + 1][170];
        firstLoad = false;
    }
}

nWidth and nHeight are static int which represent the native resolution.

However once in a blue moon I am given a ClassCastException. Why?

From my tests it seems you can cast null to int[][] though thats not actually a goal of mine.
colorData is type int[][] and I never get a NullPointerException anywhere so as far as I can tell everything works except the act of casting Serializable to int[][] and only occasionally.

Here is a stack trace, though it isn’t of much use in this case:

java.lang.RuntimeException: Unable to start activity ComponentInfo{<MYPACKAGENAMEHERE>/<MYPACKAGENAMEHERE>.MusicVisualizerActivity}: java.lang.ClassCastException: [Ljava.lang.Object;
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3701)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: [Ljava.lang.Object;
    at <MYPACKAGENAMEHERE>.Visualization_Spectral$RenderView.loadInstanceState(Visualization_Spectral.java:95)
    at <MYPACKAGENAMEHERE>.Visualization_Spectral.onCreateView(Visualization_Spectral.java:46)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
    at android.app.Activity.performStart(Activity.java:3791)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1632)
    ... 11 more
java.lang.ClassCastException: [Ljava.lang.Object;
    at <MYPACKAGENAMEHERE>.Visualization_Spectral$RenderView.loadInstanceState(Visualization_Spectral.java:95)
    at <MYPACKAGENAMEHERE>.visualization.Visualization_Spectral.onCreateView(Visualization_Spectral.java:46)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
    at android.app.Activity.performStart(Activity.java:3791)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1632)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3701)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
    at dalvik.system.NativeStart.main(Native Method)
  • 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-06T07:28:32+00:00Added an answer on June 6, 2026 at 7:28 am

    The Serializable interface if full of flaws and should be avoided whenever possible, especially in Android. From the looks of your code, your are only temporarily passing this object into a Bundle so an Activity or other component can be recreated and, if nothing else, serializing the object will provide poor performance for such a temporary need.

    The API onRetainNonConfigurationInstance() and its counterpart getLastNonConfigurationInstance() will be a much more efficient method of passing that object around if you are in the context of an Activity. If you are using the Fragment APIs, take a look at the setRetainInstance() method as well.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a helper function, which basically calls CompareTo on two objects, but does
here are two little helper methods I have made for downloading files. I have
I have a helper method that calls two other helper methods, the problem is
I have two DropDownListBoxes one is called ddlDay and the other is ddlMonth. As
I have two methods -a and -b. -a calls sometimes -b, and -b sometimes
I have the following C# helper class which retrieves a Json String from a
I have one field which is a composition of two values. This is the
I have two helper files. events_helper.rb and users_helper.rb. Both of these helper files have
I have a helper method which encrypts some data on the iPhone. If the
I have two questions about undefined method `distance_of_time_in_words' In my view I am attempting

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.