【问题标题】:android.content.res.Resources$NotFoundException: Resource ID #0x0android.content.res.Resources$NotFoundException:资源 ID #0x0
【发布时间】:2015-04-25 09:59:14
【问题描述】:

我正在按照步骤从 Linkedin 获取数据。但我收到错误:

04-25 15:19:09.516 3078-3078/app.plusconnect.com.linkedindummy E/AndroidRuntime: 致命例外:主要 android.content.res.Resources$NotFoundException:资源 ID #0x0

public class MainActivity extends ActionBarActivity {

//declaration
SocialAuthAdapter adapter;
Button linkedin_button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    adapter = new SocialAuthAdapter(new ResponseListener());

    linkedin_button = (Button)findViewById(R.id.SubmitButton);
    linkedin_button.setBackgroundResource(R.mipmap.linkedin);

    linkedin_button.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            adapter.authorize(MainActivity.this, Provider.LINKEDIN);
        }
    });

}

public class ResponseListener implements DialogListener {

    @Override
    public void onComplete(Bundle bundle) {

        adapter.getUserProfileAsync(new ProfileDataListener());
    }

    @Override
    public void onError(SocialAuthError socialAuthError) {
    }

    @Override
    public void onCancel() {
    }

    @Override
    public void onBack() {
    }
}

public class ProfileDataListener implements SocialAuthListener<Profile> {

    @Override
    public void onExecute(String s, Profile profile) {
        Log.d("Custom-UI", "Receiving Data");
        Profile profileMap = profile;
        Log.d("Custom-UI",  "Validate ID         = " + profileMap.getValidatedId());
        Log.d("Custom-UI",  "First Name          = " + profileMap.getFirstName());
        Log.d("Custom-UI",  "Last Name           = " + profileMap.getLastName());
        Log.d("Custom-UI",  "Email               = " + profileMap.getEmail());
        Log.d("Custom-UI",  "Country                  = " + profileMap.getCountry());
        Log.d("Custom-UI",  "Language                 = " + profileMap.getLanguage());
        Log.d("Custom-UI",  "Location                 = " + profileMap.getLocation());
        Log.d("Custom-UI", "Profile Image URL  = " + profileMap.getProfileImageURL());

    }

    @Override
    public void onError(SocialAuthError socialAuthError) {
    }
}

}

这是布局文件

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<TextView
    android:id="@+id/textMessage"
    android:padding="20dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Test Connect application like to fetch Profile details from LinkedIn Account."/>

<!-- Submit button -->
<Button
    android:id="@+id/SubmitButton"
    android:layout_width="200dp"
    android:layout_height="40dp"
    android:layout_marginBottom="20dp"
    android:background="@android:color/holo_blue_dark"
    android:text="Fetch from LinkedIn"
    android:textColor="@android:color/white"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"/>

我在 logcat 中收到以下错误:

04-25 15:19:09.456    3078-3078/app.plusconnect.com.linkedindummy     W/ResourceType﹕ No package identifier when getting value for resource number 0x00000000
04-25 15:19:09.477    3078-3078/app.plusconnect.com.linkedindummy W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-25 15:19:09.516    3078-3078/app.plusconnect.com.linkedindummy E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: Resource ID #0x0
        at android.content.res.Resources.getValue(Resources.java:1018)
        at android.content.res.Resources.getDrawable(Resources.java:663)
        at org.brickred.socialauth.android.SocialAuthDialog.setUpTitle(SocialAuthDialog.java:191)
        at org.brickred.socialauth.android.SocialAuthDialog.onCreate(SocialAuthDialog.java:146)
        at android.app.Dialog.dispatchOnCreate(Dialog.java:353)
        at android.app.Dialog.show(Dialog.java:257)
        at org.brickred.socialauth.android.SocialAuthAdapter$4$1.run(SocialAuthAdapter.java:649)
        at android.os.Handler.handleCallback(Handler.java:605)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4424)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
        at dalvik.system.NativeStart.main(Native Method)

问题出在哪里?有人可以帮忙吗?

【问题讨论】:

  • SocialAuthAdapter.java:649 行是什么?

标签: android


【解决方案1】:

SocialAuth 需要在drawable 文件夹中为您要集成的每项服务提供一个图像。

您可能没有这些图像,并且在尝试加载图像时SocialAuth 崩溃。要解决此问题,只需将您要使用的每个服务的图像(例如 linkedin.pngtwitter.pngfacebook.png)放入 drawable 文件夹即可。

【讨论】:

  • 我做到了,我什至为它提供的所有服务都放了所有的 png,但我仍然得到这个:获取资源编号 0x00000000 和 android.content.res.Resources$NotFoundException 的值时没有包标识符:资源 ID #0x0。请问您还有什么其他可能的问题吗?
  • 我只是注意到您在mipmap 文件夹中有一个名为linkedin 的资源。您确定服务图像在drawable 文件夹中吗?
  • 在android studio的更新版本中,即使我在drawable文件夹中添加图像,我也只能通过mipmap文件夹访问
  • 我认为这是问题的原因。使用您操作系统的文件资源管理器,打开res 文件夹,并检查是否有drawable 文件夹。如果它不可用,请手动创建,然后将图像放入此文件夹中。之后返回 Android Studio 并按 Sync Project with Gradle Files。现在您应该会看到带有服务图像的可绘制目录,并且问题应该得到解决
  • 这工作非常感谢!有一个可绘制文件夹,但它是空的。我在可绘制文件夹中添加了所有图像并且它有效。非常感谢你:) :)
【解决方案2】:

请检查链接的图片是否存在?

 linkedin_button.setBackgroundResource(R.mipmap.linkedin);

【讨论】:

    【解决方案3】:

    首先LinkedIn推出了新的Android Mobile SDK。如果您只使用https://developer.linkedin.com/docs/android-sdk,您将获得官方支持。

    看看它很简单。更喜欢使用 Android Studio 进行 LinkedIn 集成。

    【讨论】:

    【解决方案4】:

    当您收到此类错误时

     Android.Content.Res.Resources+NotFoundException: Resource ID #0x0 xamarin
    

    然后请转到android项目中的资源文件夹并用小字符命名您的图像文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 2020-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多