Question

I am building a brand new android project. It's not my 1st android app so I'm much more frustrated not being able to get rid of this error...

I use an XML File, which has for now only 3 items and NO error in the XML tab :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".gaming..MainActivity" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/fondipad"
        android:contentDescription="@string/FondDesc"

        />

    <RelativeLayout 
        android:layout_height="300dp" 
        android:layout_width="fill_parent"
        android:background="@drawable/cadremenu">

    </RelativeLayout> 
    </RelativeLayout>

Pretty simple, yay ? However, the visual tab is not rendering the cadremenu drawable (but the "fond" does)... But the cadremenu.png is in the drawable folder ! I can launch the app but only the background is rendered... I really don't know what to do... The xml file returns this exception

java.lang.NullPointerException
    at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:598)
    at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:120)
    at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:102)
    at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:233)
    at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:782)
    at android.view.View.<init>(View.java:3554)
    at android.view.View.<init>(View.java:3484)
    at android.view.ViewGroup.<init>(ViewGroup.java:464)
    at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
    at sun.reflect.GeneratedConstructorAccessor37.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    at android.view.BridgeInflater.onCreateView(BridgeInflater.java:86)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:755)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:399)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:336)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:504)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1066)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686)
    at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
    at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:292)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4136)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1458)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1481)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1271)
    at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3028)
    at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1749)
    at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:278)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4136)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1458)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1481)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1466)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1271)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3982)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3621)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

any help would be welcome !

EDIT : I already tried removing, putting back drawables, project, .... Cleaning the project, building back... I have even tried deleting & reinstalling every ADT component

Était-ce utile?

La solution

As @laato suggested, I checked my drawable/cadremenu file. I copied/pasted/overwrited the file in my project and then everything worked fine ! I actually had the same problem with all my other resources, like if my resources folder had been corrupted or something like that.

Thank you guys Hoping that someone will find help here someday

Autres conseils

This exception usually occurs due to corrupt drawables. Make sure you are able to open and view all the drawable you have linked.

enter image description here

If you happen to see any error message of this sort or are unable to view your drawable then try replacing it again with the original file or if you have downloaded it then try re-downloading it.

Because the drawable that's not showing up is itself inside a RelativeLayout, you need to put some position attributes in the cadremenu layout so that Android knows where to place it. For example, try:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="monteil.gaming.hundredious.MainActivity" >

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/fondipad"
    android:contentDescription="@string/FondDesc"

    />

<RelativeLayout 
    android:layout_height="300dp" 
    android:layout_width="fill_parent"
    **android:layout_alignParentTop="true"**
    android:background="@drawable/cadremenu">

</RelativeLayout> 
</RelativeLayout>

File -> Invalidate caches and restart

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top