Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Java

package scon;
 
import java.awt.List;
import java.io.File;
 
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
 
import javax.servlet.*;
import javax.servlet.http.*;
 
public class show {
 
	/**
	 * @param args
	 */
	public static final String MY_FOAF_FILE = "//home/ubuntu/indoor.rdf";
	public static HttpServletResponse response;
    public static HttpServletRequest request;
	public static void main(String[] args) {
		
	    
	    
		Model model = ModelFactory.createDefaultModel();
	       FileManager.get().readModel(model,MY_FOAF_FILE);
	       model.read(new File(MY_FOAF_FILE).toURI().toString());
	       String queryString =  "SELECT ?predicate ?object   WHERE {?subject ?predicate ?object .}";  
		
	       com.hp.hpl.jena.query.Query query = QueryFactory.create(queryString);
        QueryExecution qe = QueryExecutionFactory.create(query, model);
 
        com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
        ResultSetFormatter.out(System.out, results);
        response.setContentType("text/html");		
        ArrayList<rowobject> resultss = new ArrayList<rowobject>();
 
                while ( results.hasNext()) {
                    RowObject result = new RowObject();
                    QuerySolution binding = results.nextSolution();
                    result.setName(binding.get("door"));
                    result.setSymbol(binding.get("window"));
                    result.setNumber(binding.get("wind"));
                    // ...
                    resultss.add(result);
 
                }
                
                
                request.setAttribute("resultss", resultss); // Will be available as ${results} in JSP
                try {
					request.getRequestDispatcher("/wow.jsp").forward(request, response);
				} catch (ServletException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
    }
    
 

 
	}
 
PROBLEM: in unuderlined lines showing error , Exception in thread "main" java.lang.NullPointerException at scon.show.main(show.java:48), please help
Posted 28-Mar-13 18:58pm
Edited 29-Mar-13 5:36am
H.Brydon30.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There are a number of typos in your code, maybe some omitted code as well. Ignoring these, it seems that you have defined but not created either response nor request, so you will get NullPointerException when you attempt to use either of them.
 
Does your class have a constructor or a static initializer somewhere? The values in question are static, so probably shouldn't be initialized in the constructor without checking to see if they exist.
 
Try this:
 
public static HttpServletResponse response = new HttpServletResponse();
public static HttpServletRequest request = new HttpServletRequest();
 
It is not clear to me why these are static. I wouldn't code them that way...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 29 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100