Android autoLink导致渲染错误

时间:2013-08-28 12:25:22

标签: android

我在使用TextView的autoLink =“phone”选项时遇到了一些问题。 我的用户界面:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        <TextView
            android:id="@+id/personPhone"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:autoLink="phone"
            android:text="test" />
</TableLayout>

当我切换到图形布局(在ADT中)时,我得到以下错误:     渲染期间引发异常:com / android / i18n / phonenumbers / PhoneNumberUtil     Window&gt;中记录了异常详细信息。显示视图&gt;错误日志     找不到以下类:      - TextView(更改为android.widget.TextView,修复构建路径,编辑XML)

日志错误:

java.lang.NoClassDefFoundError: com/android/i18n/phonenumbers/PhoneNumberUtil
    at android.text.util.Linkify.gatherTelLinks(Linkify.java:451)
    at android.text.util.Linkify.addLinks(Linkify.java:230)
    at android.widget.TextView.setText(TextView.java:3700)
    at android.widget.TextView.setText(TextView.java:3622)
    at android.widget.TextView.<init>(TextView.java:1259)
    at android.widget.TextView.<init>(TextView.java:607)
    at sun.reflect.GeneratedConstructorAccessor16.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    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:385)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:332)
    at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:440)
    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)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)

如果我删除

android:autoLink="phone"

错误消失。

此外,如果我将“手机”更改为“电子邮件”,则不会有任何错误,但“全部”会导致相同的错误。

2 个答案:

答案 0 :(得分:22)

当我使用API​​级别18渲染视图时,我有相同的行为。它不会影响你的程序。作为一种解决方法,您可以在处理包含自动链接的布局时将“在Eclipse中呈现时使用的API版本”更改为16而不是18。图形视图上方有一个按钮,带有一个机器人图标和一个可用于更改它的编号。

Android Studio中也会出现此错误,并在http://code.google.com/p/android/issues/detail?id=59497的Android问题跟踪器中进行跟踪。

答案 1 :(得分:0)

我有简单的解决方案。您可以使用 工具:名称空间以覆盖android名称空间,例如,您可以使用下一个代码示例

<LinearLayout 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:orientation="vertical">

          <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:autoLink="all"
                tools:autoLink="none"
                />

您只需要 xmlns:tools =“http://schemas.android.com/tools”工具:autoLink =“none” 这将仅适用于预览渲染,您无法在运行时找到属性

此外,您可以将该名称空间用于其他属性,例如:

tools:text="Some text that visible only on preview"