Java Eclipse 中的 Android 应用程序:编辑文本未显示在图形布局上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24501042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android app in Eclipse: Edit text not showing on Graphical layout
提问by AJDev
I am trying to add a text field onto my Android app in Eclipse, but then I drag the Plain text
option on to the graphical layout, a message at the bottom comes up. It reads
Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V
Exception details are logged in Window > Show View > Error Log
Even when I go to Window > Show View
there is no error log option. The whole designer is useless now, because I can not use it anymore until I delete the EditText
directly from the xml. What is causing this error, and how do I fix it? I am running the latest version (as of today, 6-30-14), and Windows 8 Pro x64.
我试图在 Eclipse 中向我的 Android 应用程序添加一个文本字段,但随后我将该Plain text
选项拖到图形布局上,底部出现一条消息。它显示
Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V
Exception details are logged in Window > Show View > Error Log
即使我去Window > Show View
那里也没有错误日志选项。整个设计器现在没用了,因为我不能再使用它,直到我EditText
直接从xml中删除它。是什么导致了这个错误,我该如何解决?我正在运行最新版本(截至今天,6-30-14)和 Windows 8 Pro x64。
Here is my full layout code:
这是我的完整布局代码:
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="@string/welcome_text" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="text">
<requestFocus />
</EditText>
</RelativeLayout>
采纳答案by Fabian
Check the "Android version to use when rendering layouts" and make sure you're not using a version that ends in "W" for Android Wear (e.g.API 20: Android 4.4W). I don't believe Wear supports EditText
.
检查“渲染布局时使用的 Android 版本”,并确保您没有使用以“W”结尾的 Android Wear 版本(例如API 20:Android 4.4W)。我不相信 Wear 支持EditText
。
In both Android Studio and Eclipse, it's the dropdown with the green android in the layout preview's toolbar. You may want to set it explicitly and not allow the IDE to choose the Android version automatically.
在 Android Studio 和 Eclipse 中,它是布局预览工具栏中带有绿色 android 的下拉菜单。您可能希望明确设置它并且不允许 IDE 自动选择 Android 版本。
回答by user3168958
I changed my Android version for Android 4.2, but it still not work for me. I tried different solutions found that it only work by deleting Android 4.4W package.
我为 Android 4.2 更改了我的 Android 版本,但它仍然不适合我。我尝试了不同的解决方案,发现它只能通过删除 Android 4.4W 包来工作。
Window > Android SDK Manager > check Android 4.4W(API 20) if it was installed > Delete package
窗口 > Android SDK 管理器 > 检查 Android 4.4W(API 20) 是否已安装 > 删除包
回答by Jim C
From the Eclipse IDE, just change the API version to use for previewing, as shown in below screenshot. Instead of "Automatically Pick Best", manually select the one which works for you (API 17 worked for me).
在 Eclipse IDE 中,只需更改用于预览的 API 版本,如下面的屏幕截图所示。而不是“自动选择最佳”,而是手动选择适合您的那个(API 17 对我有用)。
回答by stu
I deleted 4.4w from my sdk install pile, which must have slipped past me last time I installed an sdk. Once I removed it it was no longer and option, and eclipse picked an sdk I did have that wasn't W and it worked.
我从我的 sdk 安装堆中删除了 4.4w,这一定是我上次安装 sdk 时从我身边溜走的。一旦我删除它,它就不再是选项,并且 eclipse 选择了一个我确实拥有的不是 W 的 sdk 并且它起作用了。
回答by Akshay Agarwal
If you are facing this on Android Studio, follow along
如果您在 Android Studio 上遇到此问题,请按照以下步骤操作
1) Uninstall Android 4.4W(API 20) from the SDK Manager
1) 从 SDK Manager 卸载 Android 4.4W(API 20)
2) Make sure you have Android SDK Build Tools 19.1 installed from the SDK Manager.
2) 确保您从 SDK Manager 安装了 Android SDK Build Tools 19.1。
3) Edit build.gradle within your app folder. Set the following two values as below
3) 在你的 app 文件夹中编辑 build.gradle。设置以下两个值如下
compileSdkVersion 19
buildToolsVersion "19.1"
4) The IDE will prompt you to sync the Gradle file with your project, click Yes.
4) IDE 会提示你将 Gradle 文件与你的项目同步,点击 Yes。
5) Open your activity file and then change the 'Android version to use when rendering layouts in IDE' to 'API 19'. This is the green colored Android Bot towards the right on the preview window
5) 打开您的活动文件,然后将“在 IDE 中呈现布局时使用的 Android 版本”更改为“API 19”。这是预览窗口右侧的绿色 Android Bot
回答by Harshil
The W in Android 4.4W suggest wearable devices. Android Wear is a wrist watch and you cannot type anything in it so you cannot use EditText on 4.4W. Change the API to 19 or less or change it to 4.4L
Android 4.4W 中的 W 表示可穿戴设备。Android Wear 是一款手表,您无法在其中输入任何内容,因此您无法在 4.4W 上使用 EditText。将API改为19以下或改为4.4L
Check it out @ https://developer.android.com/design/wear/index.html
看看@ https://developer.android.com/design/wear/index.html
You can change your previewing API version as Jim suggested if u don't want to develop apps for wearable devices.
如果您不想为可穿戴设备开发应用程序,您可以按照 Jim 的建议更改您的预览 API 版本。