0

J'essaie d'ajouter un ImageView personnalisé à mon main.xml, mais si je démarre le programme, il se ferme avec une fermeture forcée.Forcé Fermer après l'ajout de ImageView personnalisé

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/background" > 

    <test.testpkg.CustomImageView 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center_vertical" 
      android:src="@drawable/bg"/> 

</LinearLayout> 

Java:

package test.testpkg; 

import android.content.Context; 
import android.graphics.Canvas; 
import android.graphics.Color; 
import android.graphics.Paint; 
import android.widget.ImageView; 

public class CustomImageView extends ImageView { 

    public CustomImageView(Context context) { 
     super(context); 
    } 

    @Override 
    protected void onDraw(Canvas canvas) { 
     super.onDraw(canvas); 
    } 
} 

Aussi, si je lance le programme Debugger après le FC Je ne reçois que ceci: link text

Répondre

3

Debugger est inutile si vous havre de paix 't joint le code source d'Android. De plus ... il est plus utile de fournir la sortie logcat. Quoi qu'il en soit, je pense qu'il vous manque un des constructeurs. Essayez ceci:

public class CustomImageView extends ImageView { 

public CustomImageView(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
} 

public CustomImageView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
} 
// rest of your code.... 
+0

convenu, le deuxième constructeur est nécessaire. – GeekYouUp

+0

ouais maintenant c'est des fonctionnements .. étrange ADT m'a dit que je dois inclure l'un avec 1 param mais pas avec 2 .. merci! – Martin

+0

Ce n'était pas ADT, c'était Eclipse. – Cristian