Я хочу изменить текст своего текстового вида, чтобы заполнить родителя. Я следую этому вопросу: How to adjust text font size to fit textviewAndroid - NullPointerException в моем textView
Но у меня есть исключение nullPointerException, когда я пытаюсь управлять своим FontFitTextView istance.
это мой Java-код:
@SuppressLint("WrongCall") @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_avatar);
LinearLayout llyCoins = (LinearLayout) findViewById(R.id.llyCoins);
FontFitTextView textCoins = new FontFitTextView(this);
textCoins.onMeasure(llyCoins.getMeasuredWidth(),llyCoins.getMeasuredHeight());
Log.d("FLAG", "error in this line");
// rimuovo il parent da textcoins
((ViewGroup)textCoins.getParent()).removeView(textCoins);
// aggiungo textcoins alla view llycoins
llyCoins.addView(textCoins);
У меня есть исключения нулевого указателя в этой строке:
((ViewGroup)textCoins.getParent()).removeView(textCoins);
мой XML:
<LinearLayout
android:id="@+id/llyCoins"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:orientation="horizontal">
</LinearLayout>
Может кто-нибудь мне помочь?
TextCoins Isnt добавил к просмотру. Поэтому, когда вы пытаетесь удалить его, он терпит неудачу. – Aashir