2016-01-12 22 views
-3

这个错误是什么意思?如何解决它?我的错误是在主要的声明,请建议我的解决方案或任何其他方法比这更好的经纬度值与地方作为输入....谢谢。jsp scriplet中内部类的非法静态声明

<html> 
    <%@page import="javaroots.latlong.*" %> 
    <%@page import="javaroots.latlong.Location" %> 
    <%@page import="javaroots.latlong.Geometry" %> 
    <%@page import="javaroots.latlong.Result" %> 
    <%@page import="javaroots.latlong.GoogleResponse" %> 

    <%@page import="java.io.ByteArrayOutputStream" %> 
    <%@page import="org.codehaus.jackson.annotate.JsonIgnore;" %> 
    <%@page import=" java.io.IOException" %> 
    <%@page import="java.io.InputStream" %> 
    <%@page import="java.net.URL" %> 
    <%@page import="java.net.URLConnection" %> 
     <%@page import="java.net.URLEncoder" %> 
    <%@page import="java.util.*" %> 
    <%@page import="org.apache.commons.io.IOUtils" %> 
    <%@page import="org.codehaus.jackson.map.ObjectMapper" %> 




<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <h1>Hello World!</h1> 

    <%! 
     public static class AddressConverter { 
private static final String URL = "http://maps.googleapis.com/maps/api/geocode/json"; 

public GoogleResponse convertToLatLong(String fullAddress) throws IOException { 

    URL url = new URL(URL + "?address=" 
+ URLEncoder.encode(fullAddress, "UTF-8") + "&sensor=false"); 
    // Open the Connection 
    URLConnection conn = url.openConnection(); 

    InputStream in = conn.getInputStream() ; 
    ObjectMapper mapper = new ObjectMapper(); 
    GoogleResponse response = (GoogleResponse)mapper.readValue(in,GoogleResponse.class); 
    in.close(); 
    return response; 


} 

public GoogleResponse convertFromLatLong(String latlongString) throws IOException { 

    URL url = new URL(URL + "?latlng=" 
+ URLEncoder.encode(latlongString, "UTF-8") + "&sensor=false"); 
    // Open the Connection 
    URLConnection conn = url.openConnection(); 

    InputStream in = conn.getInputStream() ; 
    ObjectMapper mapper = new ObjectMapper(); 
    GoogleResponse response = (GoogleResponse)mapper.readValue(in,GoogleResponse.class); 
    in.close(); 
    return response; 

} 

public class GoogleResponse { 
    private Result[] results ; 
private String status ; 

public Result[] getResults() { 
    return results; 
} 
public void setResults(Result[] results) { 
    this.results = results; 
} 
public String getStatus() { 
    return status; 
} 
public void setStatus(String status) { 
    this.status = status; 
} 


    public static void main(String[] args) throws IOException 

    { 



    GoogleResponse res = new AddressConverter().convertToLatLong("uppal, India"); 
    if(res.getStatus().equals("OK")) 
    { 
    for(Result result : res.getResults()) 
    { 
    System.out.println("Lattitude of address is :" +result.getGeometry().getLocation().getLat()); 
    System.out.println("Longitude of address is :" + result.getGeometry().getLocation().getLng()); 
    System.out.println("Location is " + result.getFormatted_address()); 
    } 
    } 
    else 
    { 
    System.out.println(res.getStatus()); 
    } 

    System.out.println("\n"); 







} 
    }  



    public class Geometry { 

private Location location ; 

private String location_type; 

@JsonIgnore 
private Object bounds; 

@JsonIgnore 

private Object viewport; 

public Location getLocation() { 
    return location; 
} 

public void setLocation(Location location) { 
    this.location = location; 
} 

public String getLocation_type() { 
    return location_type; 
} 

public void setLocation_type(String location_type) { 
    this.location_type = location_type; 
} 

public Object getBounds() { 
    return bounds; 
} 

public void setBounds(Object bounds) { 
    this.bounds = bounds; 
} 

public Object getViewport() { 
    return viewport; 
} 

public void setViewport(Object viewport) { 
    this.viewport = viewport; 
} 




} 
public class Location { 

private String lat; 

private String lng; 

public String getLat() { 
    return lat; 
} 

public void setLat(String lat) { 
    this.lat = lat; 
} 

public String getLng() { 
    return lng; 
} 

public void setLng(String lng) { 
    this.lng = lng; 
} 
} 
public class Result { 

private String formatted_address; 

private boolean partial_match; 

private Geometry geometry; 



@JsonIgnore 
private String place_id; 
@JsonIgnore 
private Object address_components; 

@JsonIgnore 
private Object types; 

public String getFormatted_address() { 
    return formatted_address; 
} 

public void setFormatted_address(String formatted_address) { 
    this.formatted_address = formatted_address; 
} 

public boolean isPartial_match() { 
    return partial_match; 
} 

public void setPartial_match(boolean partial_match) { 
    this.partial_match = partial_match; 
} 

public Geometry getGeometry() { 
    return geometry; 
} 

public void setGeometry(Geometry geometry) { 
    this.geometry = geometry; 
} 

public Object getAddress_components() { 
    return address_components; 
} 

public void setAddress_components(Object address_components) { 
    this.address_components = address_components; 
} 

public Object getTypes() { 
    return types; 
} 

public void setTypes(Object types) { 
    this.types = types; 
} 



} 


     %> 
    </body> 
</html> 
+1

卸下'公共静态类的静态AddressConverter' –

+0

显示同样的错误:(@ E.Doroskevic –

+1

没有改善你能提供堆栈跟踪呢?所以,我们可以找出发生了什么错? –

回答

0

修饰符static只允许在常量变量声明中使用。你不能在内部类中定义静态方法。你不能使用:

public static void main(String[] args) throws IOException 

在你的内心阶层。

详情请参阅: Modifier static is only allowed in constant variable declarations

+0

它没有提供正确的解决方案 –

+0

@sangusainathvarma为了更多的理解阅读jsp规范的jsp scriptlet和jsp规范。 –