E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)

little_tu_tu 2015-11-05 08:57:07
大家帮忙看下怎么解决:
11-05 12:27:05.884: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:27:05.884: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 12:27:05.884: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-05 12:27:05.884: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-05 12:27:05.884: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
11-05 12:27:05.884: E/AndroidRuntime(329): Caused by: java.lang.ClassCastException: android.widget.ImageButton
11-05 12:27:05.884: E/AndroidRuntime(329): at com.example.calculator_fsl.MainActivity.onCreate(MainActivity.java:27)
11-05 12:27:05.884: E/AndroidRuntime(329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-05 12:27:05.884: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-05 12:27:05.884: E/AndroidRuntime(329): ... 11 more
11-05 12:38:49.153: E/AndroidRuntime(363): FATAL EXCEPTION: main
11-05 12:38:49.153: E/AndroidRuntime(363): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calculator_fsl/com.example.calculator_fsl.MainActivity}: java.lang.ClassCastException: android.widget.ImageButton
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.os.Looper.loop(Looper.java:123)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-05 12:38:49.153: E/AndroidRuntime(363): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:38:49.153: E/AndroidRuntime(363): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 12:38:49.153: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-05 12:38:49.153: E/AndroidRuntime(363): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-05 12:38:49.153: E/AndroidRuntime(363): at dalvik.system.NativeStart.main(Native Method)
11-05 12:38:49.153: E/AndroidRuntime(363): Caused by: java.lang.ClassCastException: android.widget.ImageButton
11-05 12:38:49.153: E/AndroidRuntime(363): at com.example.calculator_fsl.MainActivity.onCreate(MainActivity.java:26)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-05 12:38:49.153: E/AndroidRuntime(363): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-05 12:38:49.153: E/AndroidRuntime(363): ... 11 more
11-05 12:47:23.434: E/AndroidRuntime(398): FATAL EXCEPTION: main
11-05 12:47:23.434: E/AndroidRuntime(398): java.lang.NullPointerException
11-05 12:47:23.434: E/AndroidRuntime(398): at com.example.calculator_fsl.MainActivity.onClick(MainActivity.java:76)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.view.View.performClick(View.java:2485)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.view.View$PerformClick.run(View.java:9080)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.os.Handler.handleCallback(Handler.java:587)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.os.Looper.loop(Looper.java:123)
11-05 12:47:23.434: E/AndroidRuntime(398): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-05 12:47:23.434: E/AndroidRuntime(398): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 12:47:23.434: E/AndroidRuntime(398): at java.lang.reflect.Method.invoke(Method.java:507)
11-05 12:47:23.434: E/AndroidRuntime(398): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-05 12:47:23.434: E/AndroidRuntime(398): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-05 12:47:23.434: E/AndroidRuntime(398): at dalvik.system.NativeStart.main(Native Method)
...全文
430 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Perfect411_111 2015-11-06
  • 打赏
  • 举报
回复
代码贴一下吧,你这里在38分和47分各出现了一次错误,一共是两处错误,先查下那个类型转换错误的,再看空指针问题的
jklwan 2015-11-06
  • 打赏
  • 举报
回复
有个控件不是ImageButton,检查你的xml布局。
猴子写代码 2015-11-06
  • 打赏
  • 举报
回复
Caused by: java.lang.ClassCastException: android.widget.ImageButton 类型转换问题 把这个错误后面的贴出来,应该是android.widget.ImageButton can not cast ..... 检查EditText rsText = (EditText)findViewById(R.id.myinput); myinput 布局文件中是不是写成了ImageButton 最好贴上你的布局文件R.layout.activity_main
sanxiaochengyu 2015-11-05
  • 打赏
  • 举报
回复
76行代码是什么?错误是那个控件不是imagebutton,转换错误哦
little_tu_tu 2015-11-05
  • 打赏
  • 举报
回复
主要代码如下: package com.example.calculator_fsl; import java.util.Arrays; import bsh.Interpreter; import bsh.EvalError; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.ImageButton; public class MainActivity extends Activity implements OnClickListener{ EditText rsText = null; //显示器 boolean isClear = false; //用于记录依稀 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //fun 功能按钮 EditText rsText = (EditText)findViewById(R.id.myinput); ImageButton btnDel = (ImageButton)findViewById(R.id.delect); ImageButton btnPlu = (ImageButton)findViewById(R.id.jia); ImageButton btnMin = (ImageButton)findViewById(R.id.jian); ImageButton btnMul = (ImageButton)findViewById(R.id.cheng); ImageButton btnDiv = (ImageButton)findViewById(R.id.chu); ImageButton btnEqu = (ImageButton)findViewById(R.id.dengyu); ImageButton btnTono = (ImageButton)findViewById(R.id.c); ImageButton btnLeft = (ImageButton)findViewById(R.id.left); ImageButton btnRight = (ImageButton)findViewById(R.id.right); //num 数字按钮 ImageButton num0 = (ImageButton)findViewById(R.id.zero); ImageButton num1 = (ImageButton)findViewById(R.id.one); ImageButton num2 = (ImageButton)findViewById(R.id.two); ImageButton num3 = (ImageButton)findViewById(R.id.three); ImageButton num4 = (ImageButton)findViewById(R.id.four); ImageButton num5 = (ImageButton)findViewById(R.id.five); ImageButton num6 = (ImageButton)findViewById(R.id.six); ImageButton num7 = (ImageButton)findViewById(R.id.seven); ImageButton num8 = (ImageButton)findViewById(R.id.eight); ImageButton num9 = (ImageButton)findViewById(R.id.nine); ImageButton dot = (ImageButton)findViewById(R.id.dian); //listener btnTono.setOnClickListener(this); btnLeft.setOnClickListener(this); btnRight.setOnClickListener(this); btnDel.setOnClickListener(this); btnPlu.setOnClickListener(this); btnMin.setOnClickListener(this); btnMul.setOnClickListener(this); btnDiv.setOnClickListener(this); btnEqu.setOnClickListener(this); num0.setOnClickListener(this); num1.setOnClickListener(this); num2.setOnClickListener(this); num3.setOnClickListener(this); num4.setOnClickListener(this); num5.setOnClickListener(this); num6.setOnClickListener(this); num7.setOnClickListener(this); num8.setOnClickListener(this); num9.setOnClickListener(this); dot.setOnClickListener(this); } @Override public void onClick(View e) { ImageButton btn = (ImageButton)e; String exp = rsText.getText().toString(); if(isClear &&( btn.getContext().equals("0") ||btn.getContext().equals("1") ||btn.getContext().equals("2") ||btn.getContext().equals("3") ||btn.getContext().equals("4") ||btn.getContext().equals("5") ||btn.getContext().equals("6") ||btn.getContext().equals("7") ||btn.getContext().equals("8") ||btn.getContext().equals("9") ||btn.getContext().equals(".")) ||btn.getContext().equals("算数公式错误")){ rsText.setText(""); isClear = false; } if(btn.getContext().equals("C")){ rsText.setText(""); }else if(btn.getContext().equals("清除")){ if(exp==null || exp.trim().length()==0) return; else rsText.setText(exp.substring(0, exp.length()-1)); }else if(btn.getContext().equals("=")){ if(exp==null || exp.trim().length()==0) return; exp = exp.replaceAll("×", "*"); exp = exp.replaceAll("÷", "/"); exp = getRs(exp); if(exp.endsWith(".0")){ exp = exp.substring(0, exp.indexOf(".0")); } rsText.setText(exp); isClear = false; }else{ rsText.setText(rsText.getText()+""+btn.getContext()); isClear = false; } //按键完成后始终保持光标在最后一位 rsText.setSelection(rsText.getText().length()); } /*** * @param exp 算数表达式 * @return 根据表达式返回结果 */ private String getRs(String exp){ Interpreter bsh = new Interpreter(); Number result = null; try { exp = filterExp(exp); result = (Number)bsh.eval(exp); } catch (EvalError e) { e.printStackTrace(); isClear = true; return "算数公式错误"; } return result.doubleValue()+""; } /** * @param exp 算数表达式 * @return 因为计算过程中,全程需要有小数参与. */ private String filterExp(String exp) { String num[] = exp.split(""); String temp = null; int begin=0,end=0; for (int i = 1; i < num.length; i++) { temp = num[i]; if(temp.matches("[+-/()*]")){ if(temp.equals(".")) continue; end = i - 1; temp = exp.substring(begin, end); if(temp.trim().length() > 0 && temp.indexOf(".")<0) num[i-1] = num[i-1]+".0"; begin = end + 1; } } return Arrays.toString(num).replaceAll("[\\[\\], ]", ""); }

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧