Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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
Updated 29-Mar-13 4:36am
v2

1 solution

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:

Java
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...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900