私は Android アプリケーションに取り組んでいますが、いくつかの問題が発生しています。アプリ エンジンに接続された Android アプリを作成しました。バックエンドがデプロイされ、エンドポイントに認証を追加しています。コードはエラーなしでコンパイルされ、デバイスで起動しますが、ボタンを押して登録アクティビティに移動すると強制終了します。Logcatを確認したところ、次のように書かれていました:
RegistrationActivity.chooseAccount によって参照されるメソッド com.Google.api.client.googleapis.extensions.android.GMs.auth.GoogleAccountCredential.newChooseAccountIntent が見つかりませんでした
これを解決するにはどうすればよいですか?
プロモーター登録活動
package com.theincrowd;
import java.io.IOException;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.json.gson.GsonFactory;
import com.theincrowd.promoterendpoint.Promoterendpoint;
import com.theincrowd.promoterendpoint.model.Promoter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class PromoterRegistrationActivity extends Activity {
static final String PREF_ACCOUNT_NAME = "accountName";
static final int REQUEST_ACCOUNT_PICKER = 1;
static final String PREF_AUTH_TOKEN = "authToken";
//credentials
GoogleAccountCredential credential;
//Shared Preferences and preferred user
SharedPreferences settings;
String accountName;
boolean signedIn = false;
Promoterendpoint service;
//text fields and button stuff
EditText fn = (EditText) findViewById(R.id.firstName);
EditText ln = (EditText) findViewById(R.id.lastName);
EditText org = (EditText) findViewById(R.id.editText1);
EditText email = (EditText) findViewById(R.id.editText2);
Button regBut = (Button) findViewById(R.id.regButton);
private String firstName = fn.getText().toString();
private String lastName = ln.getText().toString();
private String organization = org.getText().toString();
private String emailAddress = email.getText().toString();
//this method gets data from the text fields and populates an instance of the Promoter model
protected void CreateNewPromoter(){
Promoter nuPromoter = new Promoter();
nuPromoter.setFirstName(firstName);
nuPromoter.setLastName(lastName);
nuPromoter.setOrganization(organization);
nuPromoter.setEmail(emailAddress);
new CreateNewPromoterTask().execute(nuPromoter);
}
//class writes new promoters to the datastore
private class CreateNewPromoterTask extends AsyncTask<Promoter, Void, Void>{
//
protected Void doInBackground(Promoter... nuPromoters){
try{
service.insertPromoter(nuPromoters[0]).execute();
}catch (IOException e){
e.printStackTrace();
}
return null;
}
}
//Include methods for setSelectedAccountName and the account picker
public void signedIn(View v){
if(!this.signedIn){
chooseAccount();
}else {
forgetAccount();
}
}
//account picker. here lies my problem...
private void chooseAccount() {
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
private void setAccountName(String accountName) {
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_ACCOUNT_NAME, accountName);
editor.commit();
credential.setSelectedAccountName(accountName);
this.accountName = accountName;
}
private void onSignedIn() {
// TODO Auto-generated method stub
this.signedIn = true;
}
private void forgetAccount() {
this.signedIn = false;
SharedPreferences.Editor editor2 = settings.edit();
editor2.remove(PREF_AUTH_TOKEN);
editor2.commit();
}
//end of account selection stuff
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_promoter_registration);
credential = GoogleAccountCredential.usingAudience(this, "server:client_id:694163602530-ims6avatrar9aagbhg6gu7ke0p7458pa.apps.googleusercontent.com");
setAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
Promoterendpoint.Builder builder = new Promoterendpoint.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential);
service = builder.build();
if (credential.getSelectedAccountName() != null){
onSignedIn();
}
//Place button here
regBut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View regBut) {
// TODO Auto-generated method stub
CreateNewPromoter();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_ACCOUNT_PICKER:
if (data != null && data.getExtras() != null) {
String accountName = data.getExtras().getString(AccountManager.KEY_ACCOUNT_NAME);
if (accountName != null) {
setAccountName(accountName);
SharedPreferences.Editor editor = settings.edit();
editor.putString(PREF_ACCOUNT_NAME, accountName);
editor.commit();
onSignedIn();
}
}
}
}
}
ログキャット:
05-31 13:28:20.860: D/dalvikvm(12545): GC_FOR_ALLOC freed 69K, 2% free 8886K/8984K, paused 45ms, total 51ms
05-31 13:28:20.883: I/dalvikvm-heap(12545): Grow heap (frag case) to 12.217MB for 3686416-byte allocation
05-31 13:28:20.915: D/dalvikvm(12545): GC_FOR_ALLOC freed <1K, 1% free 12485K/12588K, paused 32ms, total 32ms
05-31 13:28:20.954: D/dalvikvm(12545): GC_CONCURRENT freed <1K, 1% free 12485K/12588K, paused 12ms+1ms, total 41ms
05-31 13:28:21.821: D/libEGL(12545): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
05-31 13:28:22.094: D/libEGL(12545): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
05-31 13:28:22.118: D/libEGL(12545): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
05-31 13:28:22.250: D/OpenGLRenderer(12545): Enabling debug mode 0
05-31 13:28:27.688: I/dalvikvm(12545): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.newChooseAccountIntent, referenced from method com.theincrowd.PromoterRegistrationActivity.chooseAccount
05-31 13:28:27.696: W/dalvikvm(12545): VFY: unable to resolve virtual method 47: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.newChooseAccountIntent ()Landroid/content/Intent;
05-31 13:28:27.696: D/dalvikvm(12545): VFY: replacing opcode 0x6e at 0x0002
05-31 13:28:27.696: I/dalvikvm(12545): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccountName, referenced from method com.theincrowd.PromoterRegistrationActivity.setAccountName
05-31 13:28:27.696: W/dalvikvm(12545): VFY: unable to resolve virtual method 48: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.setSelectedAccountName (Ljava/lang/String;)Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;
05-31 13:28:27.696: D/dalvikvm(12545): VFY: replacing opcode 0x6e at 0x0010
05-31 13:28:27.696: W/dalvikvm(12545): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/model/Promoter; (53)
05-31 13:28:27.696: W/dalvikvm(12545): Link of class 'Lcom/theincrowd/promoterendpoint/model/Promoter;' failed
05-31 13:28:27.696: E/dalvikvm(12545): Could not find class 'com.theincrowd.promoterendpoint.model.Promoter', referenced from method com.theincrowd.PromoterRegistrationActivity.CreateNewPromoter
05-31 13:28:27.696: W/dalvikvm(12545): VFY: unable to resolve new-instance 189 (Lcom/theincrowd/promoterendpoint/model/Promoter;) in Lcom/theincrowd/PromoterRegistrationActivity;
05-31 13:28:27.696: D/dalvikvm(12545): VFY: replacing opcode 0x22 at 0x0000
05-31 13:28:27.696: I/dalvikvm(12545): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingAudience, referenced from method com.theincrowd.PromoterRegistrationActivity.onCreate
05-31 13:28:27.696: W/dalvikvm(12545): VFY: unable to resolve static method 49: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.usingAudience (Landroid/content/Context;Ljava/lang/String;)Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;
05-31 13:28:27.696: D/dalvikvm(12545): VFY: replacing opcode 0x71 at 0x000b
05-31 13:28:27.696: W/dalvikvm(12545): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/model/Promoter; (53)
05-31 13:28:27.696: W/dalvikvm(12545): Link of class 'Lcom/theincrowd/promoterendpoint/model/Promoter;' failed
05-31 13:28:27.696: D/dalvikvm(12545): DexOpt: unable to opt direct call 0x0695 at 0x02 in Lcom/theincrowd/PromoterRegistrationActivity;.CreateNewPromoter
05-31 13:28:27.696: D/dalvikvm(12545): DexOpt: unable to opt direct call 0x004e at 0x25 in Lcom/theincrowd/PromoterRegistrationActivity;.onCreate
05-31 13:28:27.696: W/dalvikvm(12545): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/Promoterendpoint$Builder; (44)
05-31 13:28:27.696: W/dalvikvm(12545): Link of class 'Lcom/theincrowd/promoterendpoint/Promoterendpoint$Builder;' failed
05-31 13:28:27.704: D/dalvikvm(12545): DexOpt: unable to opt direct call 0x0599 at 0x2a in Lcom/theincrowd/PromoterRegistrationActivity;.onCreate
05-31 13:28:27.704: D/AndroidRuntime(12545): Shutting down VM
05-31 13:28:27.704: W/dalvikvm(12545): threadid=1: thread exiting with uncaught exception (group=0x416bd930)
05-31 13:28:27.766: E/AndroidRuntime(12545): FATAL EXCEPTION: main
05-31 13:28:27.766: E/AndroidRuntime(12545): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.theincrowd/com.theincrowd.PromoterRegistrationActivity}: java.lang.NullPointerException
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.os.Looper.loop(Looper.java:137)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-31 13:28:27.766: E/AndroidRuntime(12545): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 13:28:27.766: E/AndroidRuntime(12545): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 13:28:27.766: E/AndroidRuntime(12545): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-31 13:28:27.766: E/AndroidRuntime(12545): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-31 13:28:27.766: E/AndroidRuntime(12545): at dalvik.system.NativeStart.main(Native Method)
05-31 13:28:27.766: E/AndroidRuntime(12545): Caused by: java.lang.NullPointerException
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.Activity.findViewById(Activity.java:1839)
05-31 13:28:27.766: E/AndroidRuntime(12545): at com.theincrowd.PromoterRegistrationActivity.<init>(PromoterRegistrationActivity.java:41)
05-31 13:28:27.766: E/AndroidRuntime(12545): at java.lang.Class.newInstanceImpl(Native Method)
05-31 13:28:27.766: E/AndroidRuntime(12545): at java.lang.Class.newInstance(Class.java:1319)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-31 13:28:27.766: E/AndroidRuntime(12545): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-31 13:28:27.766: E/AndroidRuntime(12545): ... 11 more
05-31 13:36:11.032: I/dalvikvm(13422): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.newChooseAccountIntent, referenced from method com.theincrowd.PromoterRegistrationActivity.chooseAccount
05-31 13:36:11.032: W/dalvikvm(13422): VFY: unable to resolve virtual method 47: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.newChooseAccountIntent ()Landroid/content/Intent;
05-31 13:36:11.032: D/dalvikvm(13422): VFY: replacing opcode 0x6e at 0x0002
05-31 13:36:11.032: I/dalvikvm(13422): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.setSelectedAccountName, referenced from method com.theincrowd.PromoterRegistrationActivity.setAccountName
05-31 13:36:11.032: W/dalvikvm(13422): VFY: unable to resolve virtual method 48: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.setSelectedAccountName (Ljava/lang/String;)Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;
05-31 13:36:11.032: D/dalvikvm(13422): VFY: replacing opcode 0x6e at 0x0010
05-31 13:36:11.040: W/dalvikvm(13422): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/model/Promoter; (53)
05-31 13:36:11.040: W/dalvikvm(13422): Link of class 'Lcom/theincrowd/promoterendpoint/model/Promoter;' failed
05-31 13:36:11.040: E/dalvikvm(13422): Could not find class 'com.theincrowd.promoterendpoint.model.Promoter', referenced from method com.theincrowd.PromoterRegistrationActivity.CreateNewPromoter
05-31 13:36:11.040: W/dalvikvm(13422): VFY: unable to resolve new-instance 189 (Lcom/theincrowd/promoterendpoint/model/Promoter;) in Lcom/theincrowd/PromoterRegistrationActivity;
05-31 13:36:11.040: D/dalvikvm(13422): VFY: replacing opcode 0x22 at 0x0000
05-31 13:36:11.040: I/dalvikvm(13422): Could not find method com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential.usingAudience, referenced from method com.theincrowd.PromoterRegistrationActivity.onCreate
05-31 13:36:11.040: W/dalvikvm(13422): VFY: unable to resolve static method 49: Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;.usingAudience (Landroid/content/Context;Ljava/lang/String;)Lcom/google/api/client/googleapis/extensions/android/gms/auth/GoogleAccountCredential;
05-31 13:36:11.040: D/dalvikvm(13422): VFY: replacing opcode 0x71 at 0x000b
05-31 13:36:11.040: W/dalvikvm(13422): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/model/Promoter; (53)
05-31 13:36:11.040: W/dalvikvm(13422): Link of class 'Lcom/theincrowd/promoterendpoint/model/Promoter;' failed
05-31 13:36:11.040: D/dalvikvm(13422): DexOpt: unable to opt direct call 0x0695 at 0x02 in Lcom/theincrowd/PromoterRegistrationActivity;.CreateNewPromoter
05-31 13:36:11.047: D/dalvikvm(13422): DexOpt: unable to opt direct call 0x004e at 0x25 in Lcom/theincrowd/PromoterRegistrationActivity;.onCreate
05-31 13:36:11.047: W/dalvikvm(13422): Unable to resolve superclass of Lcom/theincrowd/promoterendpoint/Promoterendpoint$Builder; (44)
05-31 13:36:11.047: W/dalvikvm(13422): Link of class 'Lcom/theincrowd/promoterendpoint/Promoterendpoint$Builder;' failed
05-31 13:36:11.047: D/dalvikvm(13422): DexOpt: unable to opt direct call 0x0599 at 0x2a in Lcom/theincrowd/PromoterRegistrationActivity;.onCreate
05-31 13:36:11.047: D/AndroidRuntime(13422): Shutting down VM
05-31 13:36:11.047: W/dalvikvm(13422): threadid=1: thread exiting with uncaught exception (group=0x416bd930)
05-31 13:36:11.063: E/AndroidRuntime(13422): FATAL EXCEPTION: main
05-31 13:36:11.063: E/AndroidRuntime(13422): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.theincrowd/com.theincrowd.PromoterRegistrationActivity}: java.lang.NullPointerException
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.os.Looper.loop(Looper.java:137)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-31 13:36:11.063: E/AndroidRuntime(13422): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 13:36:11.063: E/AndroidRuntime(13422): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 13:36:11.063: E/AndroidRuntime(13422): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-31 13:36:11.063: E/AndroidRuntime(13422): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-31 13:36:11.063: E/AndroidRuntime(13422): at dalvik.system.NativeStart.main(Native Method)
05-31 13:36:11.063: E/AndroidRuntime(13422): Caused by: java.lang.NullPointerException
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.Activity.findViewById(Activity.java:1839)
05-31 13:36:11.063: E/AndroidRuntime(13422): at com.theincrowd.PromoterRegistrationActivity.<init>(PromoterRegistrationActivity.java:41)
05-31 13:36:11.063: E/AndroidRuntime(13422): at java.lang.Class.newInstanceImpl(Native Method)
05-31 13:36:11.063: E/AndroidRuntime(13422): at java.lang.Class.newInstance(Class.java:1319)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-31 13:36:11.063: E/AndroidRuntime(13422): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-31 13:36:11.063: E/AndroidRuntime(13422): ... 11 more
05-31 13:36:13.407: I/Process(13422): Sending signal. PID: 13422 SIG: 9
これが役立つことを願っています...
編集: マニフェスト ファイルを追加します。
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<permission
android:name="com.theincrowd.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.theincrowd.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.WithActionBar" >
<activity
android:name="com.theincrowd.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="com.theincrowd.GCMIntentService" />
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.theincrowd" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.theincrowd" />
</intent-filter>
</receiver>
<activity
android:name="com.theincrowd.RegisterActivity"
android:launchMode="singleTop" />
<activity
android:name="com.theincrowd.PromoForkActivity"
android:label="@string/title_activity_promo_fork" >
</activity>
<activity
android:name="com.theincrowd.PromoterRegistrationActivity"
android:label="@string/title_activity_promoter_registration" >
</activity>
<activity
android:name="com.theincrowd.PartyGoerDashActivity"
android:label="@string/title_activity_party_goer_dash" >
</activity>
<activity
android:name="com.theincrowd.PartyListTabs"
android:label="@string/title_activity_party_list_tabs" >
</activity>
</application>