嗨,这是我的strings.xml。
<item><font color ="red">mnasekundę</font></item>
我将项目的颜色更改为红色,但不幸的是 LogCat说:java.lang.IllegalStateException:无法执行android的方法:onClick 这是我的OnCick方法:
public void konwertuj(View view) {
if (fromEditText.getText().toString().length() < 1) {
Toast.makeText(GlownaPredkosc.this, "Musisz wpisać dowolną liczbę", Toast.LENGTH_LONG).show();
} else {
// Get the string from the Spinners and number from the EditText
String fromString = (String) fromSpinner.getSelectedItem();
String toString = (String) toSpinner.getSelectedItem();
double input = Double.valueOf(fromEditText.getText().toString());
// Convert the strings to something in our Unit enu,
KonwerterPredkosc.Jednostka fromJednostka = KonwerterPredkosc.Jednostka.fromString(fromString);
KonwerterPredkosc.Jednostka toJednostka = KonwerterPredkosc.Jednostka.fromString(toString);
// Create a converter object and convert!
KonwerterPredkosc konwerter = new KonwerterPredkosc(fromJednostka, toJednostka);
double result = konwerter.convert(input);
toEditText.setText(String.valueOf(result));
}
P.S当字体颜色为黑色时,一切都很好。
感谢您阅读
完成输出:
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.view.View$DeclaredOnClickListener.onClick(View.java:4452)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassCastException: android.text.SpannedString cannot be cast to java.lang.String
at com.example.barto.konwerter2.GlownaPredkosc.konwertuj(GlownaPredkosc.java:73)
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4447)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
答案 0 :(得分:0)
试试这个:
toEditText.setTextColor(this.getResources().getColor(R.color.red));
不改变.xml中的任何内容。