我有这个例外,我不明白为什么会抛出它,或者我应该如何处理它.
try {
    os.writeObject(element);
} catch (IOException e) {
    e.printStackTrace();
}
哪里element是一个TransformGroup包含一些其他TransformGroups类的Atom的一个实例:
public class Atom extends Group implements Serializable{
    float pozX,pozY;
    Group group= new Group();   
    Color3f blue = new Color3f(new Color(255));
    Color3f black = new Color3f(new Color(0));
    Sphere AtSph=new Sphere();
    public Atom(final float WEIGHT, final int BOUNDS,final float radius,Color3f color)
    {
        AppSetting ap= new AppSetting(color, black);
        AtSph=new Sphere(radius,1,100,ap);
    }
}
完整的错误日志:
java.io.NotSerializableException: javax.media.j3d.TransformGroup
    at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at cls.MolecularBuilder.addAtom(MolecularBuilder.java:511)
    at cls.MolecularBuilder$Console.HidrogenItemActionPerformed(MolecularBuilder.java:897)
    at …只有子类实现了Serializable接口.
import java.io.*;
public class NewClass1{
    private int i;
    NewClass1(){
    i=10;
    }
    int getVal() {
        return i;
    }
    void setVal(int i) {
        this.i=i;
    }
}
class MyClass extends NewClass1 implements Serializable{
    private String s;
    private NewClass1 n;
    MyClass(String s) {
        this.s = s;
        setVal(20);
    }
    public String toString() {
        return s + " " + getVal();
    }
    public static void main(String args[]) {
        MyClass m = new MyClass("Serial");
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("serial.txt"));
            oos.writeObject(m); …java inheritance serialization deserialization notserializableexception
我的DAO实现在使用Tomcat7启动服务器时抛出了一个不可序列化的异常.知道是什么原因引起的吗?我的其他DAO都没有这样做.
这是班级:
package com.project.dao;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.project.model.User;
public class UserDAOImpl implements UserDAO {
    private HibernateTemplate hibernateTemplate;
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
    }
    @Override
    public void saveUser(User user) {
        hibernateTemplate.saveOrUpdate(user);
    }
    @Override
    @SuppressWarnings("unchecked")
    public List<User> listUser() {
        return hibernateTemplate.find("from User");
    }
    @Override
    @SuppressWarnings("unchecked")
    public User getUserByID(long userID) {
        List<User> users= hibernateTemplate.find("from User where id = '" + userID + "'");
        return users.size() > 0 ? users.get(0) : null;
    }
}
这是我的配置:
<beans …什么原因导致Tomcat出现这种错误?
SEVERE: Exception loading sessions from persistent storage
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:
   bean.ProjectAreaBean
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333)
 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
 at java.util.ArrayList.readObject(ArrayList.java:593)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    DelegatingMethodAccessorImpl.java:25)
在Tomcat 7上部署我的webApplication时,我将获得下面的控制台输出.重新启动服务器两次或三次后,它可以正常工作.
我正在使用JSF,Tomcat和businesslogic部分的RMI连接(在这里应该没关系?)
@ViewScoped托管bean中的@EJB导致java.io.NotSerializableException - 这里我读到了序列化.但是在这种情况下,客户端状态保存被激活,这在我的webApp中并非如此(就我的web.xml告诉我而言).那么我的视图编译ManagedBeans的序列化是必要的还是另一个失败?
这是我的启动控制台输出(Sry中的德语部分):
28.01.2011 20:25:05 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Programme\Java\jdk1.6.0_21\jre\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Programme/Java/jre6/bin/client;C:/Programme/Java/jre6/bin;C:/Programme/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Programme\Gemeinsame Dateien\Lenovo;C:\Programme\ATI Technologies\ATI.ACE\Core-Static;C:\Programme\Java\jdk1.6.0_20;C:\StudiPortal\TortoiseSVN\bin;C:\StudiPortal\apache-maven-2.0.11\bin;C:\Programme\Intel\WiFi\bin\;C:\Programme\ThinkPad\ConnectUtilities;C:\Programme\GTK2-Runtime\bin;C:\Programme\OpenVPN\bin
28.01.2011 20:25:05 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:shapeyourbody' did not find a matching property.
28.01.2011 20:25:06 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
28.01.2011 20:25:06 org.apache.coyote.ajp.AjpProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
28.01.2011 20:25:06 org.apache.catalina.startup.Catalina load
INFO: Initialization …您好我正在使用ViewScoped Bean问题是,当调用它时,我得到NotSerializableException.
这是我的Managed Bean的代码:
@ManagedBean(name="demandesBean")
@ViewScoped
public class DemandesBean implements Serializable {
    private static final long serialVersionUID = 1L;
    @ManagedProperty(value="#{demandeService}")
    private DemandeService demandeService; //A Spring Service
    @ManagedProperty(value="#{loginBean}")
    private LoginBean loginBean;
    private DemandeVO newDemande;
    @PostConstruct
    public void initData() {
        newDemande = new DemandeVO();
    }
    public void doAjouterDemande(ActionListener event) {
        demandeService.createDemande(newDemande, loginBean.getUsername());
        newDemande = new DemandeVO();
    }
    public List<DemandeVO> getListDemande() {
        return demandeService.getAllDemandesByUser(loginBean.getUsername());
    }
    public DemandeService getDemandeService() {
        return demandeService;
    }
    public void setDemandeService(DemandeService demandeService) {
        this.demandeService = demandeService;
    }
    public LoginBean …我在尝试提交表单时遇到以下异常.
javax.faces.application.ViewExpiredException: /page1.xhtml No saved view state could be found for the view identifier: /page1.xhtml
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:132)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter.doFilter(AbstractPreAuthenticatedProcessingFilter.java:94)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at …primefaces jsf-2 viewexpiredexception view-scope notserializableexception
我正在尝试编写一个简单的流处理Spark作业,它将获取每个属于用户的消息列表(JSON格式),计算每个用户的消息并打印前十个用户.
但是,当我定义Comparator>对减少的计数进行排序时,整个过程会因抛出java.io.NotSerializableException而失败.
我对Spark的maven依赖:
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.9.3</artifactId>
<version>0.8.0-incubating</version>
我正在使用的Java代码:
public static void main(String[] args) {
    JavaSparkContext sc = new JavaSparkContext("local", "spark");
    JavaRDD<String> lines = sc.textFile("stream.sample.txt").cache();
    JavaPairRDD<String, Long> words = lines
        .map(new Function<String, JsonElement>() {
            // parse line into JSON
            @Override
            public JsonElement call(String t) throws Exception {
                return (new JsonParser()).parse(t);
            }
        }).map(new Function<JsonElement, String>() {
            // read User ID from JSON
            @Override
            public String call(JsonElement json) throws Exception {
                return json.getAsJsonObject().get("userId").toString();
            }
        }).map(new PairFunction<String, String, Long>() {
            // count each …我的活动中有 5 个片段,其中一个片段一次保持活动状态。单击一个 recyclerview 项目会打开另一个片段并将当前片段放入 backstack。
  相同的代码几天前运行良好,但现在每当我单击主页按钮将应用程序置于后台时,该应用程序都会抛出NotSerializableException。我尝试将初始化变量放在 onStart 中,然后在 onStop 中给出空值,但这没有用。
  片段代码:
public class PaperListFragment extends Fragment implements Serializable {
private static final String TAG = "PaperListFragment";
private static final String QUESTIONS_FRAGMENT_TAG = "questions_fragment";
private static final String ADD_PAPER_FRAGMENT_TAG = "add_paper_fragment";
private OnFragmentActiveListener mOnFragmentActiveListener;
private TextView mHeadingText;
private Bundle mOutState;
private FirebaseAuth mAuth;
private DatabaseReference mDatabaseReference;
private ProgressBar mProgressBar;
private OnItemClickListener mOnItemClickListener;
private FloatingActionButton mFab;
private RecyclerView mRecyclerViewPaper;
private ArrayList<Paper> mPaperList = new ArrayList<>();
private Subject mSubject = …java android android-fragments notserializableexception android-studio
尝试在NetBeans中调试应用程序时收到以下错误消息:
java.io.WriteAbortedException:写入已中止; java.io.NotSerializableException:board.Board $ 1
在调试过程中,我必须在许多类中插入"implements Serializable",因为在从存储大对象的文件中读取过程中会出现异常.这并不困难,因为异常消息中已经清楚了需要注意的类.抛出我的是明显的匿名内部阶层'Board $ 1'.我不能为我的生活找出造成问题的"董事会"来源.我怎样才能做到这一点?
因为这是一个调试练习的问题,而不是代码的细节(我认为)我没有包含它,但如果它有帮助我可以轻松添加它.
java ×7
jsf ×2
jsf-2 ×2
tomcat ×2
android ×1
anonymous ×1
apache-spark ×1
catalina ×1
deployment ×1
exception ×1
inheritance ×1
java-ee ×1
java-io ×1
primefaces ×1
sorting ×1
spring ×1
tomcat7 ×1
view-scope ×1