- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我今天遇到一个关于 HIBERNATE 的奇怪问题,当我尝试将对象保存到数据库时,它给了我 java.lang.ClassCastException
。
这是错误的堆栈跟踪:
15:57:24,307 DEBUG AnnotationTransactionAttributeSource:106 - Adding transactional method 'createNombreConnexion' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
15:57:24,307 DEBUG AnnotationTransactionAttributeSource:106 - Adding transactional method 'save' with attribute: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
15:57:24,682 ERROR stderr:71 - java.lang.ClassCastException: java.lang.Long cannot be cast to ma.dataprotect.sensipro.model.NombreConnexion
15:57:24,687 ERROR stderr:71 - at ma.dataprotect.sensipro.dao.impl.NombreConnexionDaoImpl.save(NombreConnexionDaoImpl.java:30)
15:57:24,687 ERROR stderr:71 - at ma.dataprotect.sensipro.dao.impl.NombreConnexionDaoImpl.save(NombreConnexionDaoImpl.java:1)
15:57:24,687 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:57:24,687 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:57:24,692 ERROR stderr:71 - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:57:24,692 ERROR stderr:71 - at java.lang.reflect.Method.invoke(Method.java:498)
15:57:24,692 ERROR stderr:71 - at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
15:57:24,692 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
15:57:24,697 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
15:57:24,697 ERROR stderr:71 - at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
15:57:24,697 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
15:57:24,697 ERROR stderr:71 - at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
15:57:24,702 ERROR stderr:71 - at com.sun.proxy.$Proxy407.save(Unknown Source)
15:57:24,702 ERROR stderr:71 - at ma.dataprotect.sensipro.services.impl.NombreConnexionServiceImpl.createNombreConnexion(NombreConnexionServiceImpl.java:28)
15:57:24,702 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:57:24,702 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:57:24,707 ERROR stderr:71 - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:57:24,707 ERROR stderr:71 - at java.lang.reflect.Method.invoke(Method.java:498)
15:57:24,707 ERROR stderr:71 - at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
15:57:24,707 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
15:57:24,712 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
15:57:24,712 ERROR stderr:71 - at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
15:57:24,712 ERROR stderr:71 - at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
15:57:24,712 ERROR stderr:71 - at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
15:57:24,712 ERROR stderr:71 - at com.sun.proxy.$Proxy410.createNombreConnexion(Unknown Source)
15:57:24,712 ERROR stderr:71 - at ma.dataprotect.sensipro.util.LoginBean.login(LoginBean.java:85)
15:57:24,712 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
15:57:24,712 ERROR stderr:71 - at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
15:57:24,717 ERROR stderr:71 - at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
15:57:24,717 ERROR stderr:71 - at java.lang.reflect.Method.invoke(Method.java:498)
15:57:24,717 ERROR stderr:71 - at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
15:57:24,717 ERROR stderr:71 - at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
15:57:24,717 ERROR stderr:71 - at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
15:57:24,717 ERROR stderr:71 - at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:57:24,717 ERROR stderr:71 - at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:57:24,722 ERROR stderr:71 - at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
15:57:24,722 ERROR stderr:71 - at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
15:57:24,722 ERROR stderr:71 - at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
15:57:24,722 ERROR stderr:71 - at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
15:57:24,722 ERROR stderr:71 - at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
15:57:24,722 ERROR stderr:71 - at javax.faces.component.UICommand.broadcast(UICommand.java:315)
15:57:24,722 ERROR stderr:71 - at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
15:57:24,722 ERROR stderr:71 - at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
15:57:24,722 ERROR stderr:71 - at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
15:57:24,727 ERROR stderr:71 - at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
15:57:24,727 ERROR stderr:71 - at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
15:57:24,727 ERROR stderr:71 - at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
15:57:24,727 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
15:57:24,727 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
15:57:24,727 ERROR stderr:71 - at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
15:57:24,727 ERROR stderr:71 - at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
15:57:24,727 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
15:57:24,732 ERROR stderr:71 - at ma.dataprotect.sensipro.util.FiltreUTF8.doFilter(FiltreUTF8.java:48)
15:57:24,732 ERROR stderr:71 - at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
15:57:24,732 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
15:57:24,732 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
15:57:24,732 ERROR stderr:71 - at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
15:57:24,732 ERROR stderr:71 - at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
15:57:24,732 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
15:57:24,737 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
15:57:24,742 ERROR stderr:71 - at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,742 ERROR stderr:71 - at org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)
15:57:24,747 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
15:57:24,747 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
15:57:24,747 ERROR stderr:71 - at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
15:57:24,747 ERROR stderr:71 - at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
15:57:24,747 ERROR stderr:71 - at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
15:57:24,747 ERROR stderr:71 - at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
15:57:24,747 ERROR stderr:71 - at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
15:57:24,747 ERROR stderr:71 - at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
15:57:24,747 ERROR stderr:71 - at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
15:57:24,747 ERROR stderr:71 - at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
15:57:24,752 ERROR stderr:71 - at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
15:57:24,752 ERROR stderr:71 - at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
15:57:24,752 ERROR stderr:71 - at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
15:57:24,752 ERROR stderr:71 - at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
15:57:24,752 ERROR stderr:71 - at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
15:57:24,752 ERROR stderr:71 - at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
15:57:24,752 ERROR stderr:71 - at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
15:57:24,752 ERROR stderr:71 - at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
15:57:24,752 ERROR stderr:71 - at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
15:57:24,752 ERROR stderr:71 - at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
15:57:24,752 ERROR stderr:71 - at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
15:57:24,757 ERROR stderr:71 - at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
15:57:24,757 ERROR stderr:71 - at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
15:57:24,757 ERROR stderr:71 - at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
15:57:24,757 ERROR stderr:71 - at java.lang.Thread.run(Thread.java:745)
这是有问题的实体:
package ma.dataprotect.sensipro.model;
import static javax.persistence.GenerationType.IDENTITY;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@SuppressWarnings("serial")
@Entity
@Table(name = "nombre_connexion")
public class NombreConnexion implements java.io.Serializable{
private Long id;
private Organism organism;
private Date dateConnexion;
private Long nombreConn;
public NombreConnexion() {
super();
// TODO Auto-generated constructor stub
}
public NombreConnexion(Organism organism, Date dateConnexion,
Long nombreConnexion) {
super();
this.organism = organism;
this.dateConnexion = dateConnexion;
this.nombreConn= nombreConnexion;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id_organism", nullable = false)
public Organism getOrganism() {
return organism;
}
public void setOrganism(Organism organism) {
this.organism = organism;
}
@Temporal(TemporalType.DATE)
@Column(name = "date_connexion", unique=true, nullable = false)
public Date getDateConnexion() {
return dateConnexion;
}
public void setDateConnexion(Date dateConnexion) {
this.dateConnexion = dateConnexion;
}
@Column(name = "nombre_connexion", nullable = false)
public Long getNombreConn() {
return nombreConn;
}
public void setNombreConn(Long nombreConn) {
this.nombreConn = nombreConn;
}
}
通用保存方法:
@SuppressWarnings("unchecked")
public T save(T t) {
return (T) getSessionFactory().getCurrentSession().save(t);
}
产生问题的代码:
nombreConnexion = new NombreConnexion();
nombreConnexion.setOrganism(user.getOrganism());
nombreConnexion.setDateConnexion(new Date());
nombreConnexion.setNombreConn((long) 1);
System.out.println(nombreConnexion);
nombreConnexionService.createNombreConnexion(nombreConnexion);
已编辑:nombreConnexionServiceImpl.createNombreConnexion(nombreConnexion) 的代码[没什么重要的!]
public void createNombreConnexion(NombreConnexion nombreConnexion) {
nombreConnexionDao.save(nombreConnexion);
}
EDITED 2(我希望这会有所帮助):我将 id 的类型更改为 Integer 现在错误是:
16:30:46,818 ERROR stderr:71 - java.lang.ClassCastException: java.lang.Integer cannot be cast to ma.dataprotect.sensipro.model.NombreConnexion
我们正在使用 spring 和 hibernate,一切正常我不明白可能是什么问题。
最佳答案
Hibernate session 的 save() 方法返回的可序列化对象是对象的 ID(“生成的标识符”),而不是对象本身。所以它是在失败的保存方法中转换为 (T) 的。要么更改返回类型,要么返回保存的对象。
关于java - 保存时 hibernate : java. lang.ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37075671/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!