Java 无法解析符号

Java 无法解析符号,java,android,Java,Android,我尝试使用谷歌云信息 我有以下课程: package de.phcom.avs; import android.content.Context; import android.os.AsyncTask; import android.widget.Toast; import com.google.android.gms.gcm.GoogleCloudMessaging; import java.io.IOException; import java.util.logging.Level;

我尝试使用谷歌云信息

我有以下课程:

package de.phcom.avs;

import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;

import com.google.android.gms.gcm.GoogleCloudMessaging;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class GcmRegistrationAsyncTask extends AsyncTask<Void, Void, String> {
private static Registration regService = null;
private GoogleCloudMessaging gcm;
private Context context;

// TODO: change to your own sender ID to Google Developers Console project number, as per instructions above
private static final String SENDER_ID = "131952017954";

public GcmRegistrationAsyncTask(Context context) {
    this.context = context;
}

@Override
protected String doInBackground(Void... params) {
    if (regService == null) {
        Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
                // Need setRootUrl and setGoogleClientRequestInitializer only for local testing,
                // otherwise they can be skipped
                .setRootUrl("http://10.0.2.2:8080/_ah/api/")
                .setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
                    @Override
                    public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                            throws IOException {
                        abstractGoogleClientRequest.setDisableGZipContent(true);
                    }
                });
        // end of optional local run code

        regService = builder.build();
    }

    String msg = "";
    try {
        if (gcm == null) {
            gcm = GoogleCloudMessaging.getInstance(context);
        }
        String regId = gcm.register(SENDER_ID);
        msg = "Device registered, registration ID=" + regId;

        // You should send the registration ID to your server over HTTP,
        // so it can use GCM/HTTP or CCS to send messages to your app.
        // The request to your server should be authenticated if your app
        // is using accounts.
        regService.register(regId).execute();

    } catch (IOException ex) {
        ex.printStackTrace();
        msg = "Error: " + ex.getMessage();
    }
    return msg;
}

@Override
protected void onPostExecute(String msg) {
    Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    Logger.getLogger("REGISTRATION").log(Level.INFO, msg);
}
}
package de.phcom.avs;
导入android.content.Context;
导入android.os.AsyncTask;
导入android.widget.Toast;
导入com.google.android.gms.gcm.GoogleCloudMessaging;
导入java.io.IOException;
导入java.util.logging.Level;
导入java.util.logging.Logger;
公共类GcmRegistrationAsyncTask扩展了AsyncTask{
私有静态注册regService=null;
私有谷歌云通讯gcm;
私人语境;
//TODO:按照上面的说明,将您自己的发件人ID更改为Google开发者控制台项目编号
私有静态最终字符串发送器\u ID=“131952017954”;
公共GCMRRegistrationAsyncTask(上下文){
this.context=上下文;
}
@凌驾
受保护字符串doInBackground(无效…参数){
if(regService==null){
Registration.Builder=new Registration.Builder(AndroidHttp.newCompatibleTransport(),
新的AndroidJsonFactory(),null)
//仅在本地测试时需要setRootUrl和setGoogleClientRequestInitializer,
//否则可以跳过它们
.setRootUrl(“http://10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(新的GoogleClientRequestInitializer(){
@凌驾
公共无效初始化(AbstractGoogleClientRequest AbstractGoogleClientRequest)
抛出IOException{
abstractGoogleClientRequest.setDisablegzip内容(true);
}
});
//可选本地运行代码结束
regService=builder.build();
}
字符串msg=“”;
试一试{
如果(gcm==null){
gcm=GoogleCloudMessaging.getInstance(上下文);
}
字符串regId=gcm.register(发送方ID);
msg=“设备已注册,注册ID=“+regId;
//您应该通过HTTP将注册ID发送到服务器,
//因此,它可以使用GCM/HTTP或CCS向您的应用程序发送消息。
//如果您的应用程序
//正在使用帐户。
regService.register(regId.execute();
}捕获(IOEX异常){
例如printStackTrace();
msg=“错误:”+ex.getMessage();
}
返回味精;
}
@凌驾
受保护的void onPostExecute(字符串msg){
Toast.makeText(context,msg,Toast.LENGTH_LONG).show();
Logger.getLogger(“注册”).log(Level.INFO,msg);
}
}
他们说:

  • 无法解析符号“注册”
  • 无法解析符号“AndroidHttp”
  • 无法解析符号“AndroidJsonFactory”
等等。
我已经下载了谷歌API 19和21。

只是详细阐述了中东和北非的答案

您可以通过添加以下依赖项来解决此问题:

compile 'com.google.http-client:google-http-client-android:1.22.0'

您似乎没有导入其中任何一个。他们没有找到任何iPortScheck在您的项目中检查依赖项。例如,google-http-java-client。您在哪里找到此代码?代码来自: