java,spring,dependency-injectionRelated issues-Collection of common programming errors
user246
unit-tests java
The idea of using Scala to build unit tests for Java code has been thrown around. People are making the claim that Unit tests would be less effort to write because there’s less boilerplate. In addition Scala, provides other “features” to provide “better” tests. Has anyone gone through this evaluation, and can you explain the pros/cons of using Scala for Java unit testing?
System Down
java c# android
I’m a C# dev and I have plans of starting to develop apps targeting Android, which of course means Java. I have heard good things about Mono for Android and the idea of reusing my skill set is appealing, however the licensing cost (for now) is a bit prohibitive to me. On the other hand, from what I can see, Java is very similar to C#, so I’m predicting that shifting my skills to it will be more or less easy (easier than shifting to Obj-C I guess). Am I wrong in assuming that?Are there any hidden
rm -rf
java remote-access webmathematica
I’m trying to connect to a remote Mathematica 8 kernel (on a Windows machine) using J/Link. On the client machine, I put the JLinkNativeLibrary.dll file in C:\Documents and Settings\User\My Documents. But, it gives me the error message “cannot find the required native library named JLinkNativeLibrary”.Here is my codepublic static void main(String[] args) {KernelLink link;try {String jLinkDir = “C:\\Documents and Settings\\User\\My Documents”;System.setProperty(“com.wolfram.jlink.libdir”, jLinkDi
renzo7
raster gdal java
To summarize, trying to read a raster keeps giving me an UnsatisfiedLinkError that makes sense, but looking into the compiled GDAL jar, I don’t know how to fix.gdal.AllRegister(); TheFile = gdal.Open(filepath);double[] attributes = TheFile.GetGeoTransform(); extent = new int[] {TheFile.GetRasterXSize(), TheFile.GetRasterYSize()}; pixel_size = new double[] {attributes[1], attributes[5]}; corner = new double[] {attributes[0], attributes[3]};Band TheBand = TheFile.GetRasterBand(1); TheData = new do
pringlesinn
java slick
I followed some advices to learn Slick2D and when I started doing the “SimpleGame” I got my first error. Does anyone have any idea of what is it and how to fix?Sun Dec 26 23:09:12 GMT-03:00 2010 INFO:Slick Build #274 Sun Dec 26 23:09:12 GMT-03:00 2010 INFO:LWJGL Version: 2.0b1 Sun Dec 26 23:09:12 GMT-03:00 2010 INFO:OriginalDisplayMode: 1024 x 768 x 16 @60Hz Sun Dec 26 23:09:12 GMT-03:00 2010 INFO:TargetDisplayMode: 800 x 600 x 0 @0Hz Sun Dec 26 23:09:12 GMT-03:00 2010 ERROR:Could not find a val
minusSeven
java game-industry browser-based-games php
Somewhat related to Is Java viable for serious game development?I have decided to make a browser based mmo game. But the only programming language I know is Java. So I would like to know how good is java as language for browser based game development especially in terms of performance and speed compared to popular languages like PHP ? Is there any studies on this subject based on performance and speed of programming languages on browser based games ?
Brian
java android
The following code works but is slow and I know can be better, just don’t understand how to make it work. The end result is displaying the actual driving distance from the users current location to multiple locations (I’m only including two end locations here to try and save space). This way they can see which location is actually closer to where they currently are. Right now I’m making multiple calls when I know I should be able to pass in everything at once.In Locations.java, in getLastLocatio
200_success
java strings array homework sorting
What are the better solutions possible?I have a character array with different strings. There is a max size for the strings. In case a string is smaller than max size remaining places are filled with ‘-‘. Sorting has to be done on this.Example:maxStringSize = 5totalStrings = 4InputArray: w,a,t,e,r, c,a,t,-,-, f,i,v,e,-, b,a,l,l,-,-outputArray: b,a,l,l,-,-, c,a,t,-,-, f,i,v,e,-, w,a,t,e,r-public class QuestionOne {char[] mInput = {‘w’,’a’,’t’,’e’,’r’,’c’,’a’,’t’,’-‘,’-‘,’f’,’i’,’v’,’e’,’-‘,’b’,’a
hop
java optimization performance
I am trying to delete a large folders (with many levels of subfolders) over a network (i.e, on a remote machine. I have the following code and it takes 10 minutes. Is there a way to improve this, drastically ?public static boolean deleteDirectory(File directory) {File[] files = directory.listFiles(); // Value is null if the file is not an directory or if the file doesn’t existif(null!=files && files.length>0){//Gets in here only if the file is directorylong filesCount = files.length;f
syb0rg
java algorithm strings search file
I have written this code to search for a string in a .txt file. Is it possible to optimize the code so that it searches for the string in fastest manner possible? Assuming the text file would be a large one (500MB-1GB)I don’t want to use regex.import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException;public class StringFinder {public static void main(String[] args) {double count = 0,countBuffer=0,countLine=0;String lineNumber = “”;
user2390534
java spring mongodb index
we are using Spring-Data-Mongo to access our MongoDB from a Java application. In general everything works fine but I encountered one odd behavior.When initializing our Repositories in the Java code we use ensureIndex to create indices on the collections. In a unit test we read all indices from the collections as IndexInfo objects and check if those IndexInfo objects contain the fields we want to index in the member indexFields. This also worked fine when we set everything up.Now it happened that
Javi
java json spring parsing jackson
I’m using the jackson library for serializing/deserializing to/from JSON. I need that this JSON has the smallest size as possible so I’ve enabled the feature ALLOW_UNQUOTED_FIELD_NAMES to eliminate all the quotes. I know that removing quotes is not standard json, but making json small is a hard requirement of the project. The generated json works, but when I’ve trying to read the json value I’m getting an exception:org.codehaus.jackson.JsonParseException:Unexpected character (‘9’ (code 57)):was
Tomasz Nurkiewicz
java spring hibernate
We had Spring2 jar files in application. Upgraded all the Jar files to latest release and started seeing the following error message. Checked my Buildpath and classpath, cannot find anything from there. following is my spring-context.xml. xsd versions were 2.5 previously, I changes all the xsd versions to 3.0 (Depending on the latest version 3.0 and 2.3 for spring-webflow). attached my stacktrace. Any help is greatly appreciated!<?xml version=”1.0″ encoding=”UTF-8″?> <beans xmlns=”http:
MHero
java android spring rest
I’m trying to POST to a rest service using spring for android(I’m new at this)The restful service has this structure@POST @Path(“/ider”) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public SearchOutRO hashTrackInJSON(SearchInRO in);with(shortened object code):public class SearchInRO implements Serializable {private Double latitud;private Double longitud; }public class SearchOutRO implements Serializable {private Integer searchId; }so I’m trying this(from android)St
Bharat
java xml spring eclipse-virgo
I am new to virgo server. I have Virgo server 3.5.0.RELEASE which I am trying to start. But its getting failed due to the below error:[2014-02-24 20:54:39.482] ERROR GiLogServiceListener@1762fc7 org.osgi.service.log.LogService Bundle org.eclipse.gemini.blueprint.extender_1.0.2.RELEASE, FrameworkEvent ERROR org.osgi.framework.BundleException: Exception in org.eclipse.gemini.blueprint.extender.internal.boot.ChainActivator.start() of bundle org.eclipse.gemini.bluep
Tiny
spring hibernate oracle10g hql
I have a requirement to fetch selected rows from Oracle database based on ids supplied as an array, something like the SELECT … FROM table_name WHERE id IN() query. In my attempts to do so, I’m trying to use the setParameterList() method in my DAO as follows.@Service @Transactional(readOnly = true, propagation=Propagation.REQUIRES_NEW) public final class ProductImageDAO implements ProductImageService {@SuppressWarnings(“unchecked”)public List<Object[]> getOldFileName(String []id){return
Pradeep Gamage
spring jquery-ajax struts2 struts2-jquery
I am developing web project by using Spring3,struts 2 and jquery jquery-1.8.2.js. this is my jquery ajax callfunction(){var data = {};data[‘patientFETO.title’] = $(‘#idSelTitle’).val().trim(); data[‘patientFETO.firstName’] = $(‘#idFirstName’).val().trim(); data[‘patientFETO.lastName’] = $(‘#idLastName’).val().trim(); data[‘patientFETO.mobileNumber’] = $(‘#idMobileNumber’).val().trim(); data[‘patientFETO.idNumber’] = $(‘#idIDNumber’).val().trim(); data[‘patientFETO.gender’] = $(‘#idSelGender’).va
theCoder
java spring spring-mvc-test
I am using spring MVC testing: In my test case, I am passing an invalid Bar object(age with zero). The MethodArgumentNotValidException is being thrown, but it is nested inside a NestedServletException. Is there anyway to throw the MethodArgumentNotValidException exception from the controller through an existing/custom HandlerExceptionResolver, so that my current test case checkHit2 passes?Controller:@RequestMapping(value=”/test”, method = RequestMethod.POST, headers=”Accept=application/json”)@Re
user1364743
sql spring hibernate jpa hibernate-entitymanager
I just want to code a simple search engine using JPA. Here’s example of native sql request that works with PHP :”SELECT mobiles.brand, argus_waitings_mobiles_prices.mobile, argus_waitings_mobiles_prices.argus_buyer_id, “. “MATCH(mobile) AGAINST(‘$mobile_tags’ IN BOOLEAN MODE) AS pertinence “. “FROM argus_waitings_mobiles_prices “. “WHERE argus_waitings_mobiles_prices.argus_buyer_id = $buyerId “. “ORDER BY pertinence DESC “. “LIMIT 10”);I want to do the same like this but it does not work :@Overr
David Fioretti
spring grails ldap websphere websphere-7
We have a custom Grails application that is using Spring Security for LDAP authentication. The user DNs contain commas (e.g., “CN=Smith\, John,CN=Users,DC=example,DC=com”), but our admin user’s DN does not (e.g., “CN=peadmin,CN=Users,DC=example,DC=com”). When I run the application from the Grails server, which is essentially Tomcat, everything authenticates fine. When I build the WAR and deploy to WebSphere AS 7, I can only log in with the admin user. The exception in our log complains about an
Jon Seigel
oop dependency-injection inversion-of-control castle-windsor
I’m using castle windsor for a pet-project I’m working on. I’m starting to notice that I need to call the IoC container in different places in my code to create new objects. This dependency on the container makes my code harder to maintain.There are two solutions I’ve used to solve this problemI tried to create abstract factories as wrappers around the container that I could inject into parts of my application that need to create objects. This works but has some drawbacks because castle has a ha
Jeff
dependency-injection castle-windsor castle
I’m getting some very unexpected (I think) behavior with the Typed Factory facility. Basically, it’s reusing transient component instances for constructor injection with Func<T>.Here is the gist of it:// this guy is registered as service EntityFrameworkRepositoryProvider, not IRepository [Transient] public class EntityFrameworkRepositoryProvider : IRepository {public EntityFrameworkRepositoryProvider(ObjectContext objectContext, Assembly assembly){// HOLY MOLY BATMAN!! Every time I hit t
Phil Sandler
c# dependency-injection unity
My current registration code:Assembly web = Assembly.Load(“MyAssembly”); types.AddRange(web.GetTypes()); //etc.foreach (var theInterface in types.Where(t => t.IsInterface)) {var assignableType = types.Where(t => theInterface.IsAssignableFrom(t) && t != theInterface);foreach (var type in assignableType){container.RegisterType(theInterface, type);} }My generic interface and its implementations:public interface IDomainEventHandler<in T> {void Handle(T message); }public class Dom
Joel Coehoorn
c# .net dependency-injection inversion-of-control
The separation of concerns provided by IoC/DI frameworks cannot be overestimated for a large projects, but is there a place for such techniques in a small project?Can you share some real-life uses of IoC/DI frameworks you found to be useful when you were coding another small/average project.For the sake of definition:A “small project” contains 100-1000 lines of code (balpark, just to give an idea), it takes a 1-3 days to code and the lifetime of the resulting application before it gets thrown aw
John Bubriski
c# .net asp.net-mvc dependency-injection service-locator
In general does the instantiation of classes with methods, but no fields or properties, have much overhead?I’m developing an ASP.NET MVC application that heavily uses constructor injection and some controllers have up to 10 dependencies so far. But due to the high number of dependencies, I resorted to a IMyAppServiceProvider interface and class that provides generic access to all the dependencies, through the DependencyResolver in MVC 3.I ripped out all my application specific code and created
Jehof
c# dependency-injection prism unity
I thought I know a lot about Unity, but the following scenario I did not except. I´m using Unity Container to register my views for Prism as objects with a named registration like so: _unityContainer.RegisterType<object, MyDummyView>(“MyDummyViewName”);and I request instance of the view by callingobject view = _unityContainer.Resolve<object>(“MyDummyViewName”);So far so good. Now I found a bug in my system, cause I used the wrong name to resolve an instance of a view and I expected
case nelson
php dependency-injection static-variables
I would like to use this pattern to enable dependency injection in my code. I feel that it keeps with the play-doh nature of dynamic languages [1].class A {static $FOO = ‘Foo’;function __construct() {$this->foo = self::$FOO::getInstance();} }A::$FOO = ‘MockFoo’; $a = new A();Unfortunately, this doesn’t work and I get:Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM in [test.php] on line 6I can create a temporary variable to trick the parser, but is there another way?function __con
TheRock3t
spring dependency-injection bean-validation customvalidator custom-validators
I have the same problem that the guy from this thread has. More precisely I get the following error, when trying to inject a bean in my custom validator that implements CustomValidator interface (it’s a NPE when accessing the bean i wanted to inject):javax.validation.ValidationException: HV000028: Unexpected exception during isValid call. at org.hibernate.validator.internal.engine.ConstraintTree.validateSingleConstraint(ConstraintTree.java:294) at org.hibernate.validator.internal.engine.Constra
Terenced
ruby dependency-injection rspec mocking
I am having trouble mocking an injected object. For example:class Foodef initialize(bar = Bar.new)@bar = barenddef [email protected]_something_coolend end# Rspec describe Foo doit “should do something cool” domock_bar = mock(“bar”)mock_bar.stub(:do_something_cool).and_return(nil)real_foo = Foo.new(mock_bar)real_foo.runmock_bar.should_receive(:do_something_cool).onceend endIf I run this, the spec fails because it says the “do_something_cool” is never called.expected: 1 timereceived: 0 timesHowever, if I
Brian Rasmussen
c# constructor dependency-injection
I’ve long considered it a bad practice to call out to a classes dependencies from within the constructor but wasn’t able to articulate why to a colleague yesterday. Can anyone provide a good reason for NOT doing this?
Web site is in building