Java Eclipse 无法解析导入 org.hibernate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27838367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:07:54  来源:igfitidea点击:

Eclipse The import org.hibernate cannot be resolved

javaandroideclipsehibernate

提问by Naveen Gamage

I'm quite new to Android SDK. I'm trying to use Hibernate/Criteria but it gives an error.

我对 Android SDK 很陌生。我正在尝试使用 Hibernate/Criteria,但它给出了一个错误。

I have installed Hibernate following these steps.

我已经按照这些步骤安装了 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

I can see that Hibernate has been installed in Eclipse but why the error keeps showing?

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

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

error

错误

The import org.hibernate cannot be resolved

file

文件

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!"));
    }

采纳答案by Deepak Shingan

You need to add Hibernate Jar to your project classpath or to your eclipse library list.

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

Also, by adding Help-> Install New Software you are adding Hibernate plugin for eclipse and not adding Hibernate lib to your eclipse project.

此外,通过添加 Help-> Install New Software,您将为 eclipse 添加 Hibernate 插件,而不是将 Hibernate lib 添加到您的 eclipse 项目中。

Here are some links for adding jars to eclipse project or classpath:

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

How to import a jar in Eclipse

如何在 Eclipse 中导入 jar

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

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