2016-04-23 3 views
0

Also versuche ich android Entwicklung und im Versuch, dieses Programm zu lernen, aber es ist mir die Fehlermeldung geben Error:(23, 26) String types not allowed (at 'src' with value 'pen'). wenn ich versuche, es auf meinem Nexus 6.Fehler: (23, 26) String-Typen nicht erlaubt (bei 'src' mit Wert 'Stift').

Java-Code auszuführen: Import android.support.v7.app .AppCompatActivity; importieren android.os.Bundle; importieren android.widget.Button; importieren android.widget.TextView; importieren 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 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> 

Antwort

1

Die Fehlermeldung sagt deutlich, Ihre Fehler. Sie müssen eine ziehbare Referenz auf eine imageView setzen. Aber Sie setzen einen String:

android:src="pen" 

Wenn Sie ein ziehbar (Bild) mit dem Namen Stift haben, ändern Sie diese Zeile:

android:src="@drawable/pen" 
Verwandte Themen