【问题标题】:Eclipse The import org.hibernate cannot be resolvedEclipse 导入 o​​rg.hibernate 无法解决
【发布时间】:2015-01-08 10:54:17
【问题描述】:

我对 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

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

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

【问题讨论】:

  • 您是否已将休眠 jars 添加到项目的类路径中
  • 嗯,不!你是怎么做到的?

标签: java android eclipse hibernate


【解决方案1】:

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

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

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

How to import a jar in Eclipse

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

【讨论】:

  • 好的,所以类路径是 /src 但在哪里可以找到 .jars?
  • 从网上下载您需要的版本,例如:sourceforge.net/projects/hibernate/files/hibernate3
  • 我目前已经安装了 4.2.1。下载 3.* jars 可以吗,还是必须下载 4.2.1 jars?
  • 如果对版本没有特殊要求,请下载最新的4.2.1。
  • 谢谢!我已经完成了所有工作,现在错误消失了,但我收到了一个新错误Cannot instantiate the type Criteria。知道为什么会这样吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 2014-02-26
  • 2011-01-08
  • 2021-11-20
  • 2013-08-26
  • 2013-03-11
  • 1970-01-01
相关资源
最近更新 更多