LibGDX Desktop launch error - graphics

I have a game in Libgdx. It will now not run on the desktop version, or on android. When I run Main.java as desktop application, it sends these errors.. I will also post my code. Thanks.
Errors:
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/GLCommon
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:64)
at com.ahewdev.spacepace.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.graphics.GLCommon
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Desktop - Main.java code
package com.ahewdev.spacepace;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.ahewdev.spacepace.SpacePace;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.setup.resources.desktop.*;
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "spacepace";
cfg.width = 480;
cfg.height = 320;
cfg.useGL20 = false;
new LwjglApplication(new SpacePace(), cfg);
}
}
EDIT:

Related

java.lang.reflect.InvocationTargetException when using Kotlin-Mokito library

any() from Kotlin Mockito library crash with the following code
The Test Class
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.verify
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
class SimpleClassTest {
lateinit var simpleObject: SimpleClass
#Mock lateinit var injectedObject: InjectedClass
#Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}
#Test
fun testSimpleFunction() {
simpleObject = SimpleClass(injectedObject)
simpleObject.simpleFunction()
verify(injectedObject).settingDependentObject(any())
}
}
The Source Class
import com.squareup.okhttp.Protocol
import com.squareup.okhttp.Request
import com.squareup.okhttp.Response
class SimpleClass(val injectedClass: InjectedClass) {
fun simpleFunction() {
injectedClass.settingDependentObject(Response.Builder()
.request(Request.Builder().url("https://example.com").build())
.code(200)
.body(null)
.protocol(Protocol.HTTP_1_1)
.build())
}
}
open class DependentClass(response: Response) {
}
open class InjectedClass() {
lateinit var response: Response
open fun settingDependentObject(response: Response) {
this.response = response
}
}
The Crash Log
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at kotlin.reflect.jvm.internal.FunctionCaller$Constructor.call(FunctionCaller.kt:63)
at kotlin.reflect.jvm.internal.KCallableImpl$DefaultImpls.call(KCallableImpl.kt:67)
at kotlin.reflect.jvm.internal.KFunctionImpl.call(KFunctionImpl.kt:30)
at kotlin.reflect.jvm.internal.KCallableImpl$DefaultImpls.callBy(KCallableImpl.kt:103)
at kotlin.reflect.jvm.internal.KFunctionImpl.callBy(KFunctionImpl.kt:30)
at com.nhaarman.mockito_kotlin.CreateInstanceKt.newInstance(CreateInstance.kt:138)
at com.nhaarman.mockito_kotlin.CreateInstanceKt.createInstance(CreateInstance.kt:60)
at com.elyeproj.phoneinfo.SimpleClassTest.testSimpleFunction(SimpleClassTest.kt:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NullPointerException
at com.squareup.okhttp.Response.<init>(Response.java:56)
... 39 more
The library relies on the reflection to instantiate an object of a given type to be used as mockito "Any" object.
It might not be possible for those classes which have non-trivial constructors. Response is one of them.
If you could get an instance of Response somehow, you can use it instead like:
verify(injectedObject).settingDependentObject(Mockito.any<Response>() ?: someResponse)

thread-weaver with hibernate unit testing

I am trying to write a multithread unit test for my hibernate test.
I chose thread-weaver and got a little play with it.
I used the HSQL Database engine for my hibernate testing which is an in memory database.
It was working perfect until i wanted to write some multi thread unit tests.
Since i am new to thread weaver, i could make some newbie mistakes.
I knew the thread weaver is loading my class with its customized loader.
But in the #ThreadedBefore i try to set the sessionFactory for HSQL one. However, i got a bunch of error logs like
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader#ece88d2].
log4j:ERROR Could not instantiate appender named "console".
log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [com.google.testing.instrumentation.InstrumentedClassLoader#2a57a184] whereas object of type
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:179)
at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:143)
at com.amazon.amazonclicksdali.test.simpleTest.run(simpleTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at com.intellij.junit4.JUnit4TestRunnerUtil$IgnoreIgnoredTestJUnit4ClassRunner.runChild(JUnit4TestRunnerUtil.java:306)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
... 30 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
at com.google.testing.threadtester.ThreadedTestWrapper.runTests(ThreadedTestWrapper.java:71)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
... 36 more
Caused by: java.lang.NullPointerException
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClassData(InstrumentedClassLoader.java:152)
at com.google.testing.instrumentation.InstrumentedClassLoader.findClass(InstrumentedClassLoader.java:137)
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClass(InstrumentedClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1663)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1653)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1445)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at com.amazon.amazonclicksdali.test.scheduler.repository.TestSessionHelper.getSessionFactory(TestSessionHelper.java:20)
at com.amazon.amazonclicksdali.test.simpleTest.setup(simpleTest.java:45)
... 41 more
A simple test is like this
public class simpleTest {
Script<RDBInternalReportRepository> main;
Script<RDBInternalReportRepository> second;
final RDBInternalReportRepository target = new RDBInternalReportRepository();
SessionFactory sessionFactory;
RDBInternalReport internalReport1;
#Test
public void run() {
new ThreadedTestRunner().runTests(getClass(), RDBInternalReportRepository.class);
}
#ThreadedBefore
public void setup() throws Exception {
TestSessionHelper testSessionHelper = new TestSessionHelper();
sessionFactory = testSessionHelper.getSessionFactory();
target.setSessionFactory(sessionFactory);
internalReport1 = new RDBInternalReport();
internalReport1.setReferenceId("aaa");
internalReport1.setReportName("testReportName");
internalReport1.setSubmittedDate(new DateTime(2015, 1, 1, 0, 0));
internalReport1.setMarketplaceId(1);
internalReport1.setHashKey("hashValues");
internalReport1.setDedupingString("uid");
internalReport1.setState(ReportState.SUBMITTED);
internalReport1.setErrorCount(0);
target.createOrUpdateInternalReport(internalReport1);
}
#ThreadedTest
public void testSession() throws Exception {
main = new Script<RDBInternalReportRepository>(target);
second = new Script<RDBInternalReportRepository>(target);
main.addTask(new ScriptedTask<RDBInternalReportRepository>() {
#Override
public void execute() throws Exception {
IInternalReport report1 = target.getInternalReport("aaa");
releaseTo(second);
}
});
second.addTask(new ScriptedTask<RDBInternalReportRepository>() {
#Override
public void execute() throws Exception {
releaseTo(main);
}
});
new Scripter<RDBInternalReportRepository>(main, second).execute();
}
}
It fails to even load the sessionFactory which is a simple HSQL database.
It looks as though the NullPointerException is caused by getSystemResourceAsStream() returning null. See line 136 here: https://github.com/google/thread-weaver/blob/5c316abcfdfa1832df981f90cfa5c5811003012e/main/com/google/testing/instrumentation/InstrumentedClassLoader.java
I found the following question which sounds like a pretty good explanation as to what's going on: getSystemResourceAsStream() returns null
It sounds as though a fix might be to add the following to 'InstrumentedCLassLoader.findClass()'
InputStream input = getSystemResourceAsStream(resourceName);
if (input == null) {
return Thread.currentThread().getContextClassLoader().findClass(className);
}
Can you try building threadweaver from source with this fix? Alternatively, I would need to run your entire test and verify.

Javafx animation playing error

I will try to tell here the short story: I have some animations that are loaded on the screen. When they one of them is played to do a transition this error appears. I don't know what to do from here.
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.scene.Scene$ScenePulseListener.synchronizeSceneNodes(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at com.sun.javafx.tk.Toolkit$3.run(Unknown Source)
at com.sun.javafx.tk.Toolkit$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit$13.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I used also something like this, because I thought here might be the problem:
Platform.runLater(new Runnable() {
#Override public void run() {
instance.getChildren().addAll(path,polygon,text);
instance.toBack();
}
});
Thanks in advance! And if you need extra info I will be glad to update/edit the post.
EDIT:
after some more digging I found this error:
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.sun.prism.paint.Paint
at com.sun.javafx.sg.prism.NGShape.setFillPaint(Unknown Source)
at javafx.scene.shape.Shape.updatePGShape(Unknown Source)
at javafx.scene.shape.Shape.impl_updatePeer(Unknown Source)
at javafx.scene.shape.Polygon.impl_updatePeer(Unknown Source)
at javafx.scene.Node.impl_syncPeer(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.synchronizeSceneNodes(Unknown Source)
at javafx.scene.Scene$ScenePulseListener.pulse(Unknown Source)
at com.sun.javafx.tk.Toolkit$3.run(Unknown Source)
at com.sun.javafx.tk.Toolkit$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.Toolkit.runPulse(Unknown Source)
at com.sun.javafx.tk.Toolkit.firePulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit$13.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
this was caused by:
polygon.setFill(color);
where polygon is a javafx.scene.shape.Polygon and color is javafx.scene.paint.Color, but retrieved from a json file. After this I changed to:
polygon.setFill(Color.web(color.toString()));
Now all seems to work fine. Thanks!

java.io.NotSerializableException: com.microsoft.sqlserver.jdbc.SQLServerConnection [duplicate]

This question already has answers here:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException
(2 answers)
Closed 5 years ago.
I'm using Microsoft SQL Server with JSF.
I've been receiving this exception:
IOException while loading persisted sessions: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.microsoft.sqlserver.jdbc.SQLServerConnection
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: com.microsoft.sqlserver.jdbc.SQLServerConnection
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at org.apache.catalina.session.StandardSession.readObject(StandardSession.java:1587)
at org.apache.catalina.session.StandardSession.readObjectData(StandardSession.java:1060)
at org.apache.catalina.session.StandardManager.doLoad(StandardManager.java:284)
at org.apache.catalina.session.StandardManager.load(StandardManager.java:204)
at org.apache.catalina.session.StandardManager.startInternal(StandardManager.java:470)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5169)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:774)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1033)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:726)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.startup.Catalina.start(Catalina.java:620)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:303)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:431)
Caused by: java.io.NotSerializableException: com.microsoft.sqlserver.jdbc.SQLServerConnection
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at org.apache.catalina.session.StandardSession.writeObject(StandardSession.java:1663)
at org.apache.catalina.session.StandardSession.writeObjectData(StandardSession.java:1077)
at org.apache.catalina.session.StandardManager.doUnload(StandardManager.java:411)
at org.apache.catalina.session.StandardManager.unload(StandardManager.java:353)
at org.apache.catalina.session.StandardManager.stopInternal(StandardManager.java:497)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:225)
at org.apache.catalina.core.StandardContext$4.call(StandardContext.java:5391)
at org.apache.catalina.core.StandardContext$4.call(StandardContext.java:5374)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I've set the Java Bean related to the SQL Server as implements Serializable, for example
#ManagedBean
#SessionScoped
public class SqlBean implements Serializable {
private Connection conn = null;
public SqlBean() {
super();
System.out.println("Starts to read!");
String dbName = "//some dbName";
String serverip="//some serverip";
String serverport="//some serverport";
String url = "jdbc:sqlserver://"+serverip+"\\SQLEXPRESS:"+serverport+";databaseName="+dbName+"";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String databaseUserName = "//some user";
String databasePassword = "//some password";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url, databaseUserName, databasePassword);
if(conn!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
}
}
The connection is always successful. Totally lost on this. Any help will be greatly appreciated.
This is very wrong in 2 ways:
//resource injection
private Connection conn = null;
This is definitely not resource injection.
Keeping a connection open that long and sharing it across multiple requests in a HTTP session is bad design and not threadsafe.
You should rewrite all your JDBC code in such way that you acquire and close all DB resources Connection, (Prepared)Statement and ResultSet in the shortest possible scope in the very same try-finally block.
Your concrete problem is caused because a DB connection does not implement Serializable for the very simple reason that a TCP/IP connection can't be serializable.
See also:
Is it safe to use a static java.sql.Connection instance in a multithreaded system? (much similar to your design problem)
Please note that this problem is completely unrelated to JSF. You should put all that JDBC code in standalone DAO classes and make sure that all your JSF managed beans are completely free of java.sql imports. To get a step further, start learning EJB and JPA. This way all the DB interaction can be done in oneliners without any need for all the raw connection/statement/resultset mess. That's also the path you're supposed to follow if you want to go Java EE.

j2me: send sms(message) error

I am developing an app with j2me polish and for sending sms. I used javax.wireless.messaging.
but in some phones such as sony erricson and some emulators, it faces some errors related to this class, Is there any other ways to send sms that is suitable with microedition?
my code is here and it works well on emulator.
private void sendMessage() {
String phoneNumber = "sms://" + mobile;
MessageConnection localMessageConnection = null;
try {
localMessageConnection = (MessageConnection) Connector.open(phoneNumber);
TextMessage localTextMessage =
(TextMessage) localMessageConnection.newMessage(MessageConnection.TEXT_MESSAGE);
localTextMessage.setAddress(phoneNumber);
localTextMessage.setPayloadText(messageTF.getString());
localMessageConnection.send(localTextMessage);
display.setCurrent(getAlertForm("message", "success", null));
} catch (Exception localException) {
display.setCurrent(getAlertForm("message", "failure", null));
}
}
microemulator showes this error like some phones:
java.lang.NoClassDefFoundError: javax/wireless/messaging/Message
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.microemu.app.Common.startMidlet(Common.java:412)
at org.microemu.app.Common.initMIDlet(Common.java:1039)
at org.microemu.app.launcher.Launcher.commandAction(Launcher.java:121)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:189)
at org.microemu.app.ui.swing.SwingDeviceComponent$1.mousePressed(SwingDeviceComponent.java:186)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: org.microemu.app.classloader.MIDletClassLoader$LoadClassByParentException: javax.wireless.messaging.Message
at org.microemu.app.classloader.MIDletClassLoader.findClass(MIDletClassLoader.java:339)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.microemu.app.classloader.MIDletClassLoader.loadClass(MIDletClassLoader.java:213)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 30 more

Resources