Java 试图使用google-play-services_lib库,但出现诸如';GooglePlayServicesClient未解析为类型'; 我所做的

Java 试图使用google-play-services_lib库,但出现诸如';GooglePlayServicesClient未解析为类型'; 我所做的,java,android,sdk,adt,Java,Android,Sdk,Adt,我正在学习以下教程: 我想我被困在上面页面中的“在清单文件中声明库组件”中了 我猜这意味着库没有正确导入,或者我没有声明什么。事实上,我敢打赌这是我的错,我可能需要在清单文件中声明一些东西。然而,我在谷歌上搜索的“声明活动GooglePlayServicesManifest”让我相信,这个库可能没有什么需要声明的东西——否则我肯定会遇到一些例子 sdk管理器 已安装Google play服务 已安装Google API 没有要安装的更新,因此不可能有任何内容过期 导入库项目 我已导入库

我正在学习以下教程:

我想我被困在上面页面中的“在清单文件中声明库组件”中了

我猜这意味着库没有正确导入,或者我没有声明什么。事实上,我敢打赌这是我的错,我可能需要在清单文件中声明一些东西。然而,我在谷歌上搜索的“声明活动GooglePlayServicesManifest”让我相信,这个库可能没有什么需要声明的东西——否则我肯定会遇到一些例子

sdk管理器 已安装Google play服务
已安装Google API
没有要安装的更新,因此不可能有任何内容过期

导入库项目 我已导入库(右键单击我的项目>属性>android>添加>播放服务库)。
已勾选和未勾选的“is library”复选框无效

清理项目和库项目 我已多次安装并使用project>clean功能
Eclipse/ADT已多次重新启动

错误: (除其他外)。

提前谢谢你的建议。第一篇文章,所以我希望我问的是正确的和清楚的

代码 清单文件:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.atdev.atapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.atdev.atapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.atdev.atapp.Venue"
            android:label="@string/title_activity_venue"
            android:parentActivityName="com.atdev.atapp.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.atdev.atapp.MainActivity" />
        </activity>
    </application>

</manifest>
主要活动xml:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/venue_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/button1"
        android:ems="10"
        android:hint="@+id/venue_search" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/venue_search"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="34dp"
        android:layout_marginRight="31dp"
        android:onClick="sendVenueSearch"
        android:text="@string/button_venue_search" />

    <ListView
        android:id="@+id/venueList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/venue_search"
        android:layout_below="@+id/button1" >
    </ListView>

</RelativeLayout>

我在实现
GooglePlayServicesClient.ConnectionCallbacks时遇到了同样的问题,因为它无法解决导入问题,只需删除
GooglePlayServicesClient。
前缀并重新组织导入就解决了问题

  • 只需将鼠标移到“GooglePlayServicesClient.ConnectionCallbacks”功能上

  • 它会建议您将“导入GooglePlayServicesClient”作为链接。只要点击它

  • 如果问题是没有导入该库,那么您的错误现在将消失


  • 此错误与您正在使用的google play服务库版本有关

    我也遇到了同样的问题,我使用sdk管理器更新了play服务库,然后将其导入工作区

    请注意,在构建项目时,您不应该每次都构建库。在生成项目之前,请删除库文件中的勾号

    从清单中,我使用的版本是 android:versionCode=“4323030” android:versionName=“4.3.23(1069729-030)


    此版本与其他版本相比运行正常。

    导入时是否将库复制到您的工作区?是的,我在eclipse中选中了标有“复制到工作区”的框,库项目现在列在包资源管理器中我的应用程序项目下面。您确定库已添加到您的项目中吗?只需右键单击您的项目进行检查ect并选择属性,然后选择android。我是一个完全的初学者,所以我不确定我是否害怕。据我所知,将库添加到项目只涉及上面列出的步骤。当我右键单击我的应用程序项目>属性>android时,库窗格中列出了google-play-services_lib。它旁边有一个绿色勾号,并且“is library”复选框设置为true。
    编辑:为了清楚起见,我没有将任何googleplayserviceslib文件直接拖动到我自己的项目文件中,因为我相信它们应该彼此独立,所以在我的包资源管理器中,我有我的应用程序项目&下面是lib项目不要单击该复选框(is library)如果你的项目不是图书馆。非常感谢!救了我一天
        package com.atdev.atapp;
    
        import android.app.Activity;
        import android.app.Dialog;
        import android.content.Intent;
        import android.content.IntentSender;
        import android.location.Location;
        import android.os.Bundle;
        import android.support.v4.app.DialogFragment;
        import android.util.Log;
        import android.view.Menu;
        import android.view.View;
        import android.widget.EditText;
        import android.widget.Toast;
    
        import com.google.android.gms.common.ConnectionResult;
        import com.google.android.gms.common.GooglePlayServicesUtil;
        import com.google.android.gms.location.LocationClient;
    
        public class MainActivity extends Activity implements
        GooglePlayServicesClient.ConnectionCallbacks,
        GooglePlayServicesClient.OnConnectionFailedListener {
    
        // ************************************************************************
    
        // GLOBAL CONSTANTS
    
            // Define a request code to send to Google Play services. This code is returned in Activity.onActivityResult
            private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;
    
            // Set the contents of the venue search field to this string
            public final static String VENUE_SEARCH = "com.atroom.atroom.MESSAGE";
    
            // Global variable to hold the current location
            Location mCurrentLocation;
    
            // Define a DialogFragment that displays the google play services error dialog
            public static class ErrorDialogFragment extends DialogFragment {
                // Global field to contain the error dialog
                private Dialog mDialog;
                // Default constructor. Sets the dialog field to null
                public ErrorDialogFragment() {
                    super();
                    mDialog = null;
                }
                // Set the dialog to display
                public void setDialog(Dialog dialog) {
                    mDialog = dialog;
                }
                // Return a Dialog to the DialogFragment.
                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    return mDialog;
                }
            }
    
        // ********************************************************************************
    
        // GOOGLE PLAY SERVICES METHODS
    
            // Handle results returned to the FragmentActivity by Google Play services
            @Override
            protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                // Decide what to do based on the original request code
                switch (requestCode) {
                    case CONNECTION_FAILURE_RESOLUTION_REQUEST :
                        // If the result code is Activity.RESULT_OK, try to connect again
                        switch (resultCode) {
                            case Activity.RESULT_OK :
                            // Try the request again
                            break;
                        }
                }
            }
    
            // Do the following to test whether Google Play Services are available and take relevant action
            private boolean servicesConnected() {
                // Check that Google Play services is available
                int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
                    // If Google Play services is available
                    if (ConnectionResult.SUCCESS == resultCode) {
                        // In debug mode, log the status
                        Log.d("Location Updates","Google Play services is available.");
                        // Continue
                        return true;
                    // Google Play services was not available for some reason
                    } else {
                        // Get the error code
                        int errorCode = connectionResult.getErrorCode();
                        // Get the error dialog from Google Play services
                        Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                                errorCode,
                                this,
                                CONNECTION_FAILURE_RESOLUTION_REQUEST);
                        // If Google Play services can provide an error dialog
                        if (errorDialog != null) {
                            // Create a new DialogFragment for the error dialog
                            ErrorDialogFragment errorFragment =
                                    new ErrorDialogFragment();
                            // Set the dialog in the DialogFragment
                            errorFragment.setDialog(errorDialog);
                            // Show the error dialog in the DialogFragment
                            errorFragment.show(getSupportFragmentManager(),
                                    "Location Updates");
                        }
                    }
            }
    
            // Location Services calls the following on successful connection to client
            @Override
            public void onConnected(Bundle dataBundle) {
            // Display the connection status
            Toast.makeText(this, "Connected", Toast.LENGTH_SHORT).show();
            }
    
            // Location Services calls the following if connection to the location client drops because of an error.
            @Override
            public void onDisconnected() {
                // Display the connection status
                Toast.makeText(this, "Disconnected. Please re-connect.",
                        Toast.LENGTH_SHORT).show();
            }
    
            // Location Services calls the following if the attempt to connect to Location Services fails
            @Override
            public void onConnectionFailed(ConnectionResult connectionResult) {
                /*
                 * Google Play services can resolve some errors it detects.
                 * If the error has a resolution, try sending an Intent to
                 * start a Google Play services activity that can resolve
                 * error.
                 */
                if (connectionResult.hasResolution()) {
                    try {
                        // Start an Activity that tries to resolve the error
                        connectionResult.startResolutionForResult(
                                this,
                                CONNECTION_FAILURE_RESOLUTION_REQUEST);
                        /*
                         * Thrown if Google Play services canceled the original
                         * PendingIntent
                         */
                    } catch (IntentSender.SendIntentException e) {
                        // Log the error
                        e.printStackTrace();
                    }
                } else {
                    /*
                     * If no resolution is available, display a dialog to the
                     * user with the error.
                     */
                    showErrorDialog(connectionResult.getErrorCode());
                }
            }
    
    
        // *************************************************************************************
    
        // LOCATION CONNECTION METHODS
    
            // Set the current location to the last known location while a new location is being sought
            mCurrentLocation = mLocationClient.getLastLocation();
    
    
        // *************************************************************************************
    
        // ACTIVITY METHODS
    
            // Do the following when the activity is created
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main); 
                // Create a new location client, using the enclosing class to handle callbacks
                mLocationClient = new LocationClient(this, this, this);
            }
    
            // Do the following when the Activity becomes visible.
            @Override
            protected void onStart() {
                super.onStart();
                // Connect the client. This is in 'onStart' not 'onCreate' as we want to connect whenever
                // the activity becomes visible, not just when the activity is started for the first time.
                mLocationClient.connect();
            }
    
            // Do the following when the Activity is no longer visible.
            @Override
            protected void onStop() {
                // Disconnecting the client invalidates it. This saves battery - we don't want the location
                // to run in the background when the app/activity is not in use.
                mLocationClient.disconnect();
                super.onStop();
            }
    
            // Do the following when the menu is created
            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
            }
    
            // Do the following when the Venue Search button is clicked
            public void sendVenueSearch (View view) {
                Intent intent = new Intent(this, Venue.class);
                EditText editText = (EditText) findViewById(R.id.venue_search);
                String message = editText.getText().toString();
                intent.putExtra(VENUE_SEARCH, message);
                startActivity(intent);
            }
    
    }
    
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
    
        <EditText
            android:id="@+id/venue_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/button1"
            android:ems="10"
            android:hint="@+id/venue_search" >
    
            <requestFocus />
        </EditText>
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/venue_search"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="34dp"
            android:layout_marginRight="31dp"
            android:onClick="sendVenueSearch"
            android:text="@string/button_venue_search" />
    
        <ListView
            android:id="@+id/venueList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/venue_search"
            android:layout_below="@+id/button1" >
        </ListView>
    
    </RelativeLayout>