Eclipse导入org.hibernate无法解析

时间:2015-01-08 10:54:18

标签: java android eclipse hibernate

我是Android SDK的新手。我正在尝试使用Hibernate / Criteria,但它会出错。

我按照这些步骤安装了Hibernate。

Help -> Install New Software
Click on Add. Location: http://download.jboss.org/jbosstools/updates/stable/
Inside JBoss Web and Java EE Development folder, select Hibernate Tools
Click on Next

我可以看到Hibernate已经安装在Eclipse中,但为什么错误仍在显示?

import org.hibernate.Criteria;
Criteria criteria = new Criteria();

错误

The import org.hibernate cannot be resolved

文件

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.location.Location;
import android.location.LocationManager;

import android.widget.Toast;
import android.util.Log;

import org.hibernate.Criteria; 


public class MyMapActivity extends Activity {
    GoogleMap googleMap; 

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_map);
        setUpMap();
    }

    private void setUpMap() {
        // Enable MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        // Get LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // Create a criteria object to retrieve provider
        Criteria criteria = new Criteria(); //THIS IS WHERE THE ERROR IS

        // Get the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);

        // Get Current Location
        Location myLocation = locationManager.getLastKnownLocation(provider);

        //set map type
        googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        // Get latitude of the current location
        double latitude = myLocation.getLatitude();

        // Get longitude of the current location
        double longitude = myLocation.getLongitude();

        // Create a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);      

        // Show the current location in Google Map        
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

        // Zoom in the Google Map
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
        googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!"));
    }

1 个答案:

答案 0 :(得分:1)

您需要将Hibernate Jar添加到项目类路径或您的eclipse库列表中。

此外,通过添加帮助 - >安装新软件你正在为eclipse添加Hibernate插件而不是在你的eclipse项目中添加Hibernate lib。

以下是将jar添加到eclipse项目或类路径的一些链接:

How to import a jar in Eclipse

http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29