Error Serializing Object. Cause Java.io.notserializableexception
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Java : Serializing an Object with Primitive Types. Get error java.io.NotSerializableException up vote 0 down vote favorite The Class definition private class classSerial implements Serializable { private static final long serialVersionUID = 1L; String vString; boolean vBool; long vLong; int vInt; classSerial(){ //initialize members; } } I still get the error : Caused by: java.io.NotSerializableException: com.example..... When I try to do a writeObject (using an object of FileOutputStream) on an object of classSerial. From what I have read, the data types that I have used, String,boolen,long,int are Serializable. So, I do not need to implement any methods. What is it that I am missing here? LOGCAT 09-16 19:58:26.170: W/dalvikvm(4278): threadid=1: thread exiting with uncaught exception (group=0x40018560) 09-16 19:58:26.201: E/AndroidRuntime(4278): FATAL EXCEPTION: main 09-16 19:58:26.201: E/AndroidRuntime(4278): java.lang.IllegalStateException: Could not execute method of the activity 09-16 19:58:26.201: E/AndroidRuntime(4278): at android.view.View$1.onClick(View.java:2165) 09-16 19:58:26.201: E/AndroidRuntime(4278): at android.view.View.performClick(View.java:2506) 09-16 19:58:26.201: E/AndroidRuntime(4278): at android.view.View$PerformClick.run(View.java:9112) 09-16 19:58:26.201: E/AndroidRuntime(4278): at android.os.Hand
and DropEventsExpandableListViewGridViewHorizontalScrollViewImageButtonImageViewLinearLayoutListViewNotificationsPasswordProgressBarProgressDialogRadioButtonRadioGroupRatingBarRelativeLayoutScrollViewSelectorSettingsSpinnerSurfaceViewTextBoxTimePickerToastToggleButtonWebViewviewMenuOnClickListenerViewPagerwidgetAutoCompleteTextViewEditTextFrameLayoutSeekBarSlidingDrawerStackViewTextViewViewFlipperxmlgamescanvasmain loopOpenGL ESCore JavaanimationapacheANTcommonsbeanutilsconvertersArrayConvertercliBasicParsercodecbinaryBase64Base64OutputStreamcsvdbcpBasicDatasourcePoolingConnectioniocomparatorCompositeFileComparatorDirectoryFileComparatorLastModifiedFileComparatorNameFileComparatorPathFileComparatorFilenameUtilsFileUtilsIOUtilsmonitorFileAlterationMonitorlang3CharUtilsClassPathUtilsmathFractionNumberUtilsStringUtilsloggingLogfactorynetCookieStoreFTPClientURLClassLoaderURLConnectionluceneappletaspectjbeanscajoCharacterclassComperablecryptoDesign PatternsdecoratorstrategyGenericsGradlegsonGsonBuilderstreamJsonReaderJsonWriterioBufferedInputStreamBufferedOutputStreamBufferedReaderBufferedWriterByteArrayInputStreamByteArrayOutputStreamConsoleDataInputStreamDataOutputStreamExternalizableFileFileDescriptorFileInputStreamFilenameFilterFileOutputStreamFileReaderFileWriterInputStreamInputStreamReaderIOExceptionObjectInputStreamObjectOutputStreamOutputStreamPrintWriterRandomAccessFileSerializableStreamTokenizerStringReaderStringWriterjsonJacksonJSON.Simplejunitl
Error in Java java.io.NotSerializableException: org.apache.log4j.Logger error says that instance of org.apache.lo4j.Logger is not Serializable. This error http://javarevisited.blogspot.com/2012/12/javaionotserializableexception-orgapache-log4j-logger-error-exception-fix.html comes when we use log4j for logging in Java and create Logger in a Serializable class e.g. any domain class or POJO which we want https://forums.databricks.com/questions/369/how-do-i-handle-a-task-not-serializable-exception.html to store in HttpSession or want to serialize it. As we know from 10 Java Serialization interview question that, if you have a non serializable error serializing class as member in a Serializable class, it will throw java.io.NotSerializableException Exception. Look at the below code : public class Customer implements Serializable{ private Logger logger = Logger.getLogger(Customer.class) ...... } If instance of Customer will be stored in HttpSession or Serialized externally it will throw "java.io.NotSerializableException: org.apache.log4j.Logger" because here error serializing object. logger instance is neither static or transient and it doesn't implement Serializable or Externalzable interface. How to solve java.io.NotSerializableException: org.apache.log4j.Logger Solving java.io.NotSerializableException: org.apache.log4j.Logger is simple, you have to prevent logger instance from default serializabtion process, either make it transient or static. Making it static final is preferred option due to many reason because if you make it transient than after deserialization logger instance will be null and any logger.debug() call will result in NullPointerException in Java because neither constructor not instance initializer block is called during deserialization. By making it static and final you ensure that its thread-safe and all instance of Customer class can share same logger instance, By the way this error is also one of the reason Why Logger should be declared static and final in Java program. Just make following code change to fix java.io.NotSerializableException: org.apache.log4j.Logger in Java. public class Customer implements Serializable{
10 |600 characters needed characters left characters exceeded ▼ Viewable by all users Viewable by moderators Viewable by moderators and the original poster Advanced visibility Viewable by all users 4 Answers Sort Votes Created Oldest 0 Answer by cfregly · Mar 08, 2015 at 11:13 PM If you see this error: org.apache.spark.SparkException: Job aborted due to stage failure: Task not serializable: java.io.NotSerializableException: ... The above error can be triggered when you intialize a variable on the driver (master), but then try to use it on one of the workers. In that case, Spark Streaming will try to serialize the object to send it over to the worker, and fail if the object is not serializable. Consider the following code snippet:NotSerializable notSerializable = new NotSerializable(); JavaRDD