4

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 > Show View > Error Log 中找不到以下类:- 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"

错误消失。

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

4

2 回答 2

22

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

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

于 2013-08-28T18:25:28.087 回答
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"tools:autoLink="none" 这将仅适用于预览渲染,您无法在运行时找到该属性

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

tools:text="Some text that visible only on preview"
于 2014-01-01T18:19:01.770 回答