我正在制作一个android应用程序,并且该应用程序的组件之一被设计为在二进制文件中将数字转换为十进制数。每次运行它都会崩溃。我如何从二进制转换为Java中的十进制(使用android studio)
public void Button0Clicked(View v)
{
TextView myText = (TextView)findViewById(R.id.textView);
if (firstType == true)
{
myText.setText("");
firstType = false;
}
myText.setText(myText.getText() + "0");
}
public void Button1Clicked(View v)
{
TextView myText = (TextView)findViewById(R.id.textView);
if (firstType == true)
{
myText.setText("");
firstType = false;
}
myText.setText(myText.getText() + "1");
}
public void Conversion(View view)
{
TextView myText = (TextView)findViewById(R.id.textView);
int decimalValue = Integer.parseInt(myText.getText().toString(),2);
TextView result = (TextView)findViewById(R.id.textView2);
result.setText(decimalValue);
}
我已经缩小问题到一些问题与的Integer.parseInt()函数,是我错了执行?
堆栈跟踪
07-04 09:43:17.806 29832-29832/com.example.jay.myapplication2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.jay.myapplication2, PID: 29832
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x271a
at android.content.res.Resources.getText(Resources.java:244)
at android.widget.TextView.setText(TextView.java:3888)
at com.example.jay.myapplication2.MyActivity.Conversion(MyActivity.java:66)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
它崩溃时的错误是什么?它抛出异常吗?它是什么? –
在Logcat中,它表示“java.lang.IllegalStateException:无法执行活动的方法” – user3806093
您可以使用logcat添加一个堆栈跟踪到问题中。 –