0

I'm getting this error while I try to view my layouts in the graphical layout in ADT. The project runs fine and there were no problems with this at first. In addition,if I start a new project and open a layout xml file in the graphical layout its loading it fine. these are the xml file codes:

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

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/tot"
    android:textSize="40sp" />

<Button
    android:id="@+id/btn_Add"
    android:layout_width="450sp"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/add" />

<Button
    android:id="@+id/btn_Sub"
    android:layout_width="450sp"
    android:layout_height="wrap_content"
    android:layout_marginTop="14dp"
    android:gravity="center"
    android:text="@string/sub" />

</LinearLayout>

Logcat:

java.lang.NullPointerException
at android.graphics.Bitmap_Delegate.nativeWidth(Bitmap_Delegate.java:296)
at android.graphics.Bitmap.nativeWidth(Bitmap.java)
at android.graphics.Bitmap.getWidth(Bitmap.java:917)
at android.graphics.Bitmap.getScaledWidth(Bitmap.java:965)
at android.graphics.drawable.BitmapDrawable.computeBitmapSize(BitmapDrawable.java:183)
at android.graphics.drawable.BitmapDrawable.setBitmap(BitmapDrawable.java:191)
at android.graphics.drawable.BitmapDrawable.<init>(BitmapDrawable.java:604)
at android.graphics.drawable.BitmapDrawable.<init>(BitmapDrawable.java:114)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:239)
at com.android.layoutlib.bridge.bars.CustomBar.loadIcon(CustomBar.java:212)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:204)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:171)
at com.android.layoutlib.bridge.bars.FakeActionBar.<init>(FakeActionBar.java:38)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:347)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:336)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:333)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:451)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1545)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1302)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1059)
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.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:774)
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.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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)
Zachinio
  • 11
  • 1
  • 6

4 Answers4

1

You are right. I do face these types of errors soon. Following fix works for me.

1)In xml mode. Select all code, copy it.

2)Create new layout file. Paste code.

3) Delete old file. Rename new file to previous file name.

Have fun.

Adnan
  • 5,025
  • 5
  • 25
  • 44
0

You cannot get an error while just trying to view your layout in a Graphical Layout. These errors are probably the previous the run-time errors you got when u ran your project or may be some other projects.

Clean your logs, by "clear-log" button available in the Logcat console and you will be fine.

Edit 1:

So this is not your Logcat errors (run-time errors). This is your compile-time errors.

I noticed that you have given hard-coded width to your button. This is probably not a right approach. Give it "wrap_content". Also u should never give width & height's to views in "sp". Always use 'dp' if you have to. 'sp' is normally meant for "text" font size. You might wanna check out this SO link for more clarification on sp, dp.

Community
  • 1
  • 1
epiphany27
  • 517
  • 1
  • 10
  • 23
  • I have tried this many times..when I try to open the graphic layout this shown:java.lang.NullPointerException Exception details are logged in Window > Show View > Error Log – Zachinio Sep 28 '13 at 20:58
0

If you are still having this problem, right click on the layout file and elect to open with XML Editor, as opposed to the Android Common XML Editor.

Undo
  • 25,519
  • 37
  • 106
  • 129
0

Found the problem with this, my xml file was under a subfolder inside drawable, Im using Android Studio. This is what I initially did:

  1. Secondary click in drawable
  2. New File
  3. New file was assign to xxhdpi sub-folder
  4. Eventually select xml file

This is the re-do (fix):

  1. Secondary click in drawbable folder
  2. New/Drawable Resource
  3. New Resource is added directly to drawable folder

Please let me know if I helped you.

cutiko
  • 9,887
  • 3
  • 45
  • 59