spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

File path gives NullPointer


You can't reference /public/ from your service code. The mapping is only accessible from the Servlet context after Spring's handlers resolve it to /resources/public/.

Use javax.servlet.ServletContext and Spring's ServletContextResource to get the resource in your webapp folder.

@Autowired
private ServletContext servletContext;

public static List<File> getFileList() {
    Resource resource = new
ServletContextResource(servletContext,
"/resources/public");
    File folder = resource.getFile();
    File[] listOfFiles = folder.listFiles();
    list.addAll(Arrays.asList(listOfFiles));

    return list;
}

Categories : Java

Related to : File path gives NullPointer
p:graphicImage streamContent nullpointer
What is the scope of the bean, it should be View or Session scoped, and you will have to change the way you access your bean. For the dynamically created images, two requests are being sent. One to render the HTML, that renders the img tag. Than the second, fired based on the src attribute. The model must retain the values accross the subsequent requests. all explained beautifully here Display im

Categories : Java
Attribute set in onCreate, causes NullPointer in onResume
You get your Relation in a different thread (since it is executed in background). This means that the set is not actually done in onCreate() but sometimes later, so the 'done' method might be called after onResume() depending on how slow the querying is. If that happens, then you'll get a null pointer exception indeed.

Categories : Java
Butterknife fragment rotation giving NullPointer
On orientation change, the application will call onDestroy(). In your case this will reset the ButterKnife injection by calling 'ButterKnife.reset'. But onCreateView is not called on orientation change lifecycle. The issue may get solved if you move the ButterKnife injection call to onViewCreated from onCreateView.

Categories : Java
setImageResource to an array of drawables throws nullpointer exception
use Int Array in the Place of Integer Array Int[] orbitalBodies = {R.drawable.dres, R.drawable.duna, R.drawable.eeloo, R.drawable.eve, R.drawable.jool, R.drawable.kerbin, R.drawable.kerbol, R.drawable.moho}; int planetId = getIntent.getExtras().getInt("intOrbitalId"); if(planetId!=null) { ImageView img = (ImageView)findViewById(R.id.image); img.setImageResource(orbitalBodies[planetId]); } Bec

Categories : Android
Recently Add
Concurrent collection to 50/50 read/write
How to get unique members of object class (groupofUniqueNames) from an ldap server using java
Custom error reporting: how to log down function arguments (and possibly locals) in an exception handler?
Websphere MQ message redelivery
How to use BigDecimal to achieve following code instead of using double or float?
What exactly do the service() method of this HttpServlet?
Why does the Java API use int instead of short or byte?
Hibernate. One to one mapping without cross references
How to pass array to a java method
BooleanFieldEditor doesn't load value from PreferenceStore
NoClassDefFoundError when I call the class through commnad line
Shopizer Search
Java - Bank System + Transaction Function
Hadoop security using Apache DS / Apache Directory Studio
Multiple property-placeholder with overlapping locations does not work?
could not remove/add jpanel in jframe
Java garbage collection verbose not working
If child class has a variable with same name as private variable in parent what will be used?
Jackson parse json with a one-to-many relationship in a single step
Excel opens wrong view after generating in Apache POI
On Switch How to use logic operator on case JAVA
Java: What is the absolut first second in Calendar?
Waiting One Second for a button click, if button not clicked call function
Fastest way to extract part of a large JSON File
copy directory operation using linux command in java
Figuring out how to Format Printing
Why does @FunctionalInterface have a RUNTIME retention?
Collision detection Libgdx rectangles
Cannot find symbol in method changeRecL but declared in main method
Receiving "java.net.SocketException: Connection reset" when connecting from dotnet client to a java server
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.