简体   繁体   English

错误:(23,26)不允许使用字符串类型(在'src'中值为'pen')。

[英]Error:(23, 26) String types not allowed (at 'src' with value 'pen').?

So i'm trying to learn android development and im trying this program but its giving me the error Error:(23, 26) String types not allowed (at 'src' with value 'pen'). 因此,我试图学习android开发和即时尝试此程序,但它给我错误Error:(23, 26) String types not allowed (at 'src' with value 'pen'). when i try to run it on my Nexus 6. 当我尝试在Nexus 6上运行它时。

Java Code: import android.support.v7.app.AppCompatActivity; Java代码:import android.support.v7.app.AppCompatActivity; import android.os.Bundle; 导入android.os.Bundle; import android.widget.Button; 导入android.widget.Button; import android.widget.TextView; 导入android.widget.TextView; import android.widget.EditText; 导入android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button ImageButton = (Button)findViewById(R.id.Image);

        ImageButton.setOnClickListener(
                new Button.OnClickListener(){
                    public void onClick(View v)
                    {
                        TextView NL = (TextView)findViewById(R.id.Asd)
                        NL.setText("AAA");
                    }
                }
        );


    }
}

XML code: XML代码:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.bassammetwally.anew.MainActivity">
    <RelativeLayout
        android:layout_width="400dp"
        android:layout_height="50dp"
        android:background="#3955a1">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Learning program"
            android:textColor="#ffffff"
            android:textSize="30dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="8dp"
            android:id="@+id/Asd"/>
        <ImageButton
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:src="pen"
            android:layout_marginLeft="330dp"
            android:layout_marginTop="5dp"
            android:scaleType="fitXY"
            android:adjustViewBounds="true"
            android:id="@+id/image"/>
        </RelativeLayout>
</LinearLayout>

ManiFest: 表现:

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.A.anew">

        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>

    </manifest>

The error message says your error clearly. 错误消息清楚地表明了您的错误。 You have to set a drawable reference to an imageView. 您必须设置对imageView的可绘制引用。 But you set a string: 但是您设置了一个字符串:

android:src="pen"

If you have a drawable(image) named pen, change that line to: 如果您有一个名为pen的drawable(image),请将该行更改为:

android:src="@drawable/pen"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:Android Studio中不允许使用字符串类型(在“主题”中值为“”) - Error : String types not allowed (at 'theme' with value ") in android studio 错误:不允许使用字符串类型(在&#39;layout_height&#39;中,值为&#39;wrap content&#39;)。 activity_main.xml中 - Error: String types not allowed (at 'layout_height' with value 'wrap content'). activity_main.xml 错误:(453,69)不允许的字符串类型(在“ activity_horizo​​ntal_margin”处,值为“) - Error:(453, 69) String types not allowed (at 'activity_horizontal_margin' with value '') 自定义枚举属性提供错误不允许使用字符串类型 - Custom enum attribute gives error String types not allowed Android动画-不允许使用字符串类型 - Android Animation - String types not allowed 错误:(23,39)错误:类型不兼容:视图无法转换为上下文 - Error:(23, 39) error: incompatible types: View cannot be converted to Context layout_toRightOf:不允许的字符串类型 - layout_toRightOf: String types not allowed 如何修复我的Android Studio IDE? (错误23,24;错误26,13,缺少类和渲染问题) - How can I repair my Android Studio IDE? (Error 23,24 ; Error 26,13 , missing classes and render problems) 错误:(26、21)错误:找不到符号方法setText(String) - Error:(26, 21) error: cannot find symbol method setText(String) 有关字符串加密计划的错误:(char)(ch + key)%26 - The error about string encryption scheduling : (char) (ch + key) % 26
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM