其他分享
首页 > 其他分享> > 尝试在Android中添加帐户时获取例外

尝试在Android中添加帐户时获取例外

作者:互联网

我正在尝试为用户创建一种在手机上创建帐户的方法,该帐户最终会通过应用程序同步到他们的联系人.我现在正在模拟器中工作,所以我要去Menu-Dev Tools-AccountsTester来测试我拥有的东西.当我单击AccountsTester时,我在LogCat中收到以下错误代码:

03-08 18:58:31.996: ERROR/AndroidRuntime(403): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.development/com.android.development.AccountsTester}: android.content.res.Resources$NotFoundException: String resource ID #0x0
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.os.Looper.loop(Looper.java:123)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread.main(ActivityThread.java:3647)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at java.lang.reflect.Method.invokeNative(Native Method)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at java.lang.reflect.Method.invoke(Method.java:507)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at dalvik.system.NativeStart.main(Native Method)
03-08 18:58:31.996: ERROR/AndroidRuntime(403): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.content.res.Resources.getText(Resources.java:201)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.content.res.Resources.getString(Resources.java:254)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.content.Context.getString(Context.java:183)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at com.android.development.AccountsTester.initializeAuthenticatorsSpinner(AccountsTester.java:147)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at com.android.development.AccountsTester.onCreate(AccountsTester.java:63)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
03-08 18:58:31.996: ERROR/AndroidRuntime(403):     ... 11 more

正如您所看到的,没有@ line显示我的代码中发生错误的位置.我谷歌搜索了一些突出的线路,但找不到与我的问题有关的任何内容.有没有人知道这里发生了什么?如果您有任何信息可以用来帮助解答我没有包含的内容,请告诉我…谢谢!

AccountsTester将调用的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">

  <ScrollView android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingTop="5dip"
        android:paddingLeft="20dip"
        android:paddingRight="20dip"
        android:paddingBottom="13dip">

        <TextView android:id="@+id/account_login_message"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"/>

        <TextView 
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Username"/>

        <EditText android:id="@+id/account_login_username_edittext"
            android:singleLine="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:minWidth="250dip"
            android:scrollHorizontally="true"
            android:capitalize="none"
            android:autoText="false"
            android:inputType="text"/>

        <TextView android:id="@+id/account_login_username_fixed"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:singleLine="true"
            android:layout_marginTop="2dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <TextView
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="bold"
            android:singleLine="true"
            android:layout_marginTop="2dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password"/>

        <EditText android:id="@+id/account_login_password_edittext"
            android:singleLine="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:minWidth="250dip"
            android:scrollHorizontally="true"
            android:capitalize="none"
            android:autoText="false"
            android:inputType="textPassword"/>

        <TextView android:id="@+id/account_login_message_bottom"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dip"/>

        </LinearLayout>
    </ScrollView>

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#c6c3c6"
        android:minHeight="54dip"
        android:paddingLeft="2dip"
        android:paddingTop="4dip"
        android:paddingRight="2dip">

        <Button android:id="@+id/account_login_ok_button"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_horizontal"
            android:minWidth="100dip"
            android:text="Sign In"
            android:onClick="handleLogin"/>

        </FrameLayout>
</LinearLayout>

我没有在那里调用单个字符串…我的活动引用了几次字符串,但它引用的字符串肯定在那里,当我输入它时我看到它们,并且我无论如何都会在Eclipse中收到错误.

解决方法:

这里的诀窍是,在我创建帐户所需的xml / authenticator文件中,我用“App Name”填充了android:label字段,如下所示:

android:label="App Here"

我需要做的是为它调用一个资源.所以我创建了一个名为label的字符串并将名称放在那里,它工作正常.

标签:android,user-accounts
来源: https://codeday.me/bug/20190614/1237852.html