Question

J'ai créé Android XML Étalez avec quelques composants personnalisés. Mais quand je sauve le fichier XML que j'obtiens l'erreur. Depuis ce temps est mon poing avec des composants personnalisés (widgets) Je ne sais pas pourquoi je reçois cette erreur. Ceci est mon code xml.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginTop="12dp"
android:orientation="vertical"
android:background="@drawable/layout_bg">

<LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_gravity="center_horizontal"
    android:paddingLeft="12dp"
    android:paddingRight="12dp"
    android:paddingTop="30dp">

  <kankan.wheel.widget.WheelView android:id="@+id/day"
        android:layout_height="wrap_content"
        android:layout_width="46dp"/>
    <kankan.wheel.widget.WheelView android:id="@+id/month"
        android:layout_height="wrap_content"
        android:layout_width="100dp"/>
    <kankan.wheel.widget.WheelView android:id="@+id/year"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"/> 


</LinearLayout>

Et voici l'erreur que je reçois. Je dois dire qu'il n'y a pas une telle valeur des ressources dans le fichier R.java

erreur

! NotFoundException: Impossible détermination valeur des ressources. 0x7F020009

android.content.res.Resources $ NotFoundException: Impossible de résoudre la valeur des ressources: 0x7F020009. à com.android.layoutlib.bridge.BridgeResources.throwException (BridgeResources.java:546) à com.android.layoutlib.bridge.BridgeResources.getDrawable (BridgeResources.java:131) à kankan.wheel.widget.WheelView.initResourcesIfNecessary (WheelView.java:427) à kankan.wheel.widget.WheelView.calculateLayoutWidth (WheelView.java:482) à kankan.wheel.widget.WheelView.onMeasure (WheelView.java:518) à android.view.View.measure (View.java:7964) à android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:3023) à android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:888) à android.widget.LinearLayout.measureHorizontal (LinearLayout.java:619) à android.widget.LinearLayout.onMeasure (LinearLayout.java:280) à android.view.View.measure (View.java:7964) à android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:3023) à android.widget.LinearLayout.measureChildBeforeLayout (LinearLayout.java:888) à android.widget.LinearLayout.measureVertical (LinearLayout.java:350) à android.widget.LinearLayout.onMeasure (LinearLayout.java:278) à android.view.View.measure (View.java:7964) à android.view.ViewGroup.measureChildWithMargins (ViewGroup.java:3023) à android.widget.FrameLayout.onMeasure (FrameLayout.java:245) à android.view.View.measure (View.java:7964) à com.android.layoutlib.bridge.Bridge.computeLayout (Bridge.java:443) à com.android.ide.common.rendering.LayoutLibrary.createLegacySession (LayoutLibrary.java:404) à com.android.ide.common.rendering.LayoutLibrary.createSession (LayoutLibrary.java:285) à com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge (GraphicalEditorPart.java:1506) à com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge (GraphicalEditorPart.java:1312) à com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout (GraphicalEditorPart.java:1043) à com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onXmlModelChanged (GraphicalEditorPart.java:1005) à com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.xmlModelChanged (LayoutEditor.java:303) à com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor $ XmlModelStateListener.modelChanged (AndroidXmlEditor.java:1213) à org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.fireModelChanged (AbstractStructuredModel.java:553) à org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.internalModelChanged (AbstractStructuredModel.java:887) à org.eclipse.wst.sse.core.internal.model.AbstractStructuredModel.changedModel (AbstractStructuredModel.java:382) à org.eclipse.wst.xml.core.internal.document.DOMModelImpl.changedModel (DOMModelImpl.java:167) à com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.wrapEditXmlModel (AndroidXmlEditor.java:803) à com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode.setPropertyValue (UiElementNode.java:1885) à com.android.ide.eclipse.adt.internal.editors.layout.gle2.CanvasViewInfo.setPropertyValue (CanvasViewInfo.java:320) à org.eclipse.ui.views.properties.PropertySheetEntry.valueChanged (PropertySheetEntry.java:782) à org.eclipse.ui.views.properties.PropertySheetEntry.setValue (PropertySheetEntry.java:723) à org.eclipse.ui.views.properties.PropertySheetEntry.applyEditorValue (PropertySheetEntry.java:146) à org.eclipse.ui.views.properties.PropertySheetEntry $ 1.applyEditorValue (PropertySheetEntry.java:103) à org.eclipse.jface.viewers.CellEditor 1.run $ (CellEditor.java:333) à org.eclipse.core.runtime.SafeRunner.run (SafeRunner.java:42) à org.eclipse.ui.internal.JFaceUtil 1.run $ (JFaceUtil.java:49) à org.eclipse.jface.util.SafeRunnable.run (SafeRunnable.java:175) à org.eclipse.jface.viewers.CellEditor.fireApplyEditorValue (CellEditor.java:331) à com.android.ide.eclipse.adt.internal.editors.ui.EditableDialogCellEditor.handleDefaultSelection (EditableDialogCellEditor.java:264) à com.android.ide.eclipse.adt.internal.editors.ui.EditableDialogCellEditor $ 1.widgetDefaultSelected (EditableDialogCellEditor.java:83) à org.eclipse.swt.widgets.TypedListener.handleEvent (TypedListener.java:119) à org.eclipse.swt.widgets.EventTable.sendEvent (EventTable.java:84) à org.eclipse.swt.widgets.Widget.sendEvent (Widget.java:1053) à org.eclipse.swt.widgets.Display.runDeferredEvents (Display.java:4066) à org.eclipse.swt.widgets.Display.readAndDispatch (Display.java:3657) à org.eclipse.ui.internal.Workbench.runEventLoop (Workbench.java:2640) à org.eclipse.ui.internal.Workbench.runUI (Workbench.java:2604) à org.eclipse.ui.internal.Workbench.access 4 $ (Workbench.java:2438) à org.eclipse.ui.internal.Workbench 7.run $ (Workbench.java:671) à org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332) à org.eclipse.ui.internal.Workbench.createAndRunWorkbench (Workbench.java:664) à org.eclipse.ui.PlatformUI.createAndRunWorkbench (PlatformUI.java:149) à org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115) à org.eclipse.equinox.internal.app.EclipseAppHandle.run (EclipseAppHandle.java:196) à org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication (EclipseAppLauncher.java:110) à org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start (EclipseAppLauncher.java:79) à org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:369) à org.eclipse.core.runtime.adaptor.EclipseStarter.run (EclipseStarter.java:179) à sun.reflect.NativeMethodAccessorImpl.invoke0 (natif Méthode) à sun.reflect.NativeMethodAccessorImpl.invoke (Information inconnue Source) à sun.reflect.DelegatingMethodAccessorImpl.invoke (Information inconnue Source) à java.lang.reflect.Method.invoke (Information inconnue Source) à org.eclipse.equinox.launcher.Main.invokeFramework (Main.java:619) à org.eclipse.equinox.launcher.Main.basicRun (Main.java:574) à org.eclipse.equinox.launcher.Main.run (Main.java:1407) à org.eclipse.equinox.launcher.Main.main (Main.java:1383)

S'il vous plaît aidez-moi à résoudre cette erreur. Merci à l'avance.

Était-ce utile?

La solution

Il y a une ressource qui ne se trouve pas. Il pourrait être par exemple le @drawable/layout_bg que vous utilisez?

Si ce n'est pas, jetez un oeil à ces deux lignes:

initResourcesIfNecessary(WheelView.java:427) 
calculateLayoutWidth(WheelView.java:482) 

Vous appelez quelque chose qui demande une ressource qui est pas là (un identifiant, un drawable, etc etc).

Autres conseils

Pour résoudre ce problème tout ce que je devais faire est de retirer l'importation suivante:

import kankan.wheel.R; // remove this line

qui est ajouté automatiquement lorsque vous copiez et collez le code de l'échantillon démo

Retirez la ligne en surbrillance dans cette capture d'écran

Tout est correct. S'il vous plaît vérifier le format d'image pour layout_bg dans le dossier drawable. Formats pris en charge:

1.jpg 2.png 3.bmp

(par exemple: Android accepte .jpg, .jpeg pas).

Je résolu ce problème en "try-catching" l'accès aux ressources dans la méthode

     initResourcesIfNecessary

Je comprends que ce n'est pas la solution idéale, mais au moins maintenant je peux modifier mes mises en page dans le temps de conception.

La méthode modifiée est inférieure à

        private void initResourcesIfNecessary() {


    if (centerDrawable == null) {
        try {
            centerDrawable = getContext().getResources().getDrawable(R.drawable.wheel_val);
        } catch (Exception ex) {
            centerDrawable = null;
        }
    }

    if (topShadow == null) {
        try {
            topShadow = new GradientDrawable(Orientation.TOP_BOTTOM, SHADOWS_COLORS);
        } catch (Exception ex) {
            topShadow = null;
        }
    }

    if (bottomShadow == null) {
        try {
            bottomShadow = new GradientDrawable(Orientation.BOTTOM_TOP, SHADOWS_COLORS);
        } catch (Exception ex) {
            bottomShadow = null;
        }
    }
    try {
        setBackgroundResource(R.drawable.wheel_bg);
    } catch (Exception ex) {
        setBackgroundResource(0);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top