![](/img/trans.png)
[英]Error : String types not allowed (at 'theme' with value ") in android studio
[英]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').
當我嘗試在Nexus 6上運行它時。
Java代碼:import android.support.v7.app.AppCompatActivity; 導入android.os.Bundle; 導入android.widget.Button; 導入android.widget.TextView; 導入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代碼:
<?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>
表現:
<?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>
錯誤消息清楚地表明了您的錯誤。 您必須設置對imageView的可繪制引用。 但是您設置了一個字符串:
android:src="pen"
如果您有一個名為pen的drawable(image),請將該行更改為:
android:src="@drawable/pen"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.