2016-05-23 16 views
0

アクティビティーを実行しようとしています。残念ながら、私たちは間違っています。レイアウトに問題があるようです。私を助けてください。アクティビティーを開始できません。java.lang.RuntimeException:アクティビティーを開始できません。

ありがとうございます。

ベースの活動のxml:http://pastie.org/10848446

ベースの活動のjava:http://pastie.org/10848447

ログイン活動のxml:http://pastie.org/10848450

ログイン活動のjava:http://pastie.org/10848454

カスタムフォントのタイプフェイス:http://pastie.org/10848460

カスタムBu tton:

エラー:あなたのレイアウトファイルでhttp://paste.ofcode.org/r7dmcAqWbvLCEhb7EffvTi

+0

ログインXMLコードの行番号12とは何ですか? RelativeLayoutのlogin.xmlの高さの –

+0

はwrap_contentでなければなりません。 親レイアウトとしてRelativeLayoutを使用する必要はなく、scrollViewの外側で何もしない場合は、ScrollViewを親レイアウトにしてください。 –

+0

高さと幅の相対的なレイアウトです。 – user3563459

答えて

0

これらのクラスのためのチェックError inflating class com.app.nbhc.utilities.CustomTypefacedButton

+0

customtypefacedbuttonのコードが追加されました – user3563459

+0

xmlでこのクラスをどこで使用しましたか? –

+0

ログイン用にフルXMLファイルを投稿してください。サインインボタンが表示されない –

0

あなたはCustomTypefacedButtonを使用している場所を見つけるので、私は私のblog

の上にそれを使用する方法をチェックアウトすることができませんでした

これは私が使用しているものであり、コード、利用可能なブログの説明 -

ファイル - attrs.xml

<declare-styleable name="TextFont"> 
    <attr name="customFont" format="string" /> 
</declare-styleable> 

クラス - FontCache.java

public class FontCache { 

    private static Hashtable<String, Typeface> fontCache = new Hashtable<>(); 

    /** 
    * Gets the typeface from Asset folder 
    * @param name path to the font within asset folder 
    * @param context context of the view 
    * @return 
    */ 
    public static Typeface get(String name, Context context) { 
     Typeface tf = fontCache.get(name); 
     if (tf == null) { 
      try { 
       tf = Typeface.createFromAsset(context.getAssets(), name); 
      } catch (Exception e) { 
       return null; 
      } 
      fontCache.put(name, tf); 
     } 
     return tf; 
    } 
} 

/** 
* Sets a font on a TextView 
* 
* @param textview view for which font mentioned needs to be changed 
* @param font path of the font where it has been saved (Generally within asset folder) 
* @param context Context where view has been used 
*/ 
public static void setCustomFont(TextView textview, String font, Context context) { 
    if (font == null) { 
     return; 
    } 
    Typeface typeface = FontCache.get(font, context); 
    if (typeface != null) { 
     textview.setTypeface(typeface); 
    } 
} 

クラス - CustomFontHelper.java

public class CustomFontHelper { 
    /** 
    * Sets a font on a textview based on the custom com.my.package:font attribute 
    * If the custom font attribute isn't found in the attributes nothing happens 
    * 
    * @param textview 
    * @param context 
    * @param attrs 
    */ 
    public static void setCustomFont(TextView textview, Context context, AttributeSet attrs) { 
     TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextFont); 
     String font = typedArray.getString(R.styleable.TextFont_customFont); 
     setCustomFont(textview, font, context); 
     typedArray.recycle(); 
    } 

    /** 
    * Sets a font on a TextView 
    * 
    * @param textview view for which font mentioned needs to be changed 
    * @param font path of the font where it has been saved (Generally within asset folder) 
    * @param context Context where view has been used 
    */ 
    public static void setCustomFont(TextView textview, String font, Context context) { 
     if (font == null) { 
      return; 
     } 
     Typeface typeface = FontCache.get(font, context); 
     if (typeface != null) { 
      textview.setTypeface(typeface); 
     } 
    } 

    /** 
    * Sets a font on a paint based on the custom com.my.package:font attribute 
    * If the custom font attribute isn't found in the attributes nothing happens 
    * 
    * @param paint 
    * @param context 
    * @param attrs 
    */ 
    public static void setCustomFont(Paint paint, Context context, AttributeSet attrs){ 
     TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextFont); 
     String font = typedArray.getString(R.styleable.TextFont_customFont); 
     setCustomFont(paint, font, context); 
     typedArray.recycle(); 
    } 

    /** 
    * Changing font of Paint element 
    * @param paint text element of which font needs to be changed 
    * @param font 
    * @param context 
    */ 
    public static void setCustomFont(Paint paint, String font, Context context) { 
     if (font == null) { 
      return; 
     } 
     Typeface typeface = FontCache.get(font, context); 
     if (typeface != null) { 
      paint.setTypeface(typeface); 
     } 
    } 
} 

クラス - FontButton.java

public class FontButton extends Button { 

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

    public FontButton(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     CustomFontHelper.setCustomFont(this, context, attrs); 
    } 

    public FontButton(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
     CustomFontHelper.setCustomFont(this, context, attrs); 
    } 
} 

フォントのstring.xmlパスで資産フォルダ内のXMLで

<string name="font_light">fonts/SourceSansPro-Regular.ttf</string> 
<string name="font_semibold">fonts/SourceSansPro-Semibold.ttf</string> 
<string name="font_regular">fonts/SourceSansPro-Regular.ttf</string> 
<string name="font_bold">fonts/Oxygen-Bold.ttf</string> 

これは、私はそれを使用している方法です -

<com.COMPANY.APP.app.custom.FontButton xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/lbl_welcome" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/img_logo" 
    android:layout_marginTop="20dp" 
    android:gravity="center" 
    android:text="YOUR SHOPPING COMPANION!" 
    android:textColor="@color/toolbar" 
    android:textSize="@dimen/font_12" 
    app:customFont="@string/font_semibold" /> 
+0

でクラスを拡張したことがありますか?エラーで自分のコードを更新しました。 – user3563459

+0

@ user3563459、 'ScrollView'の最初の子' RelativeLayout'を削除するとどうなりますか? –

関連する問題