- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Android 应用程序和 Java 的新手,一直在制作一个简单的应用程序,一切都很顺利,直到我打开模拟器并出现以下错误“不幸的是,您的应用程序已停止”。这是我的主要 Activity.java 文件:
package com.firstprogram;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity {
LinearLayout layout1;
EditText number1text;
EditText number2text;
Button calcButton;
TextView answerText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
layout1 = new LinearLayout (this);
number1text = new EditText (this);
number2text = new EditText (this);
calcButton = new Button (this);
answerText = new TextView (this);
layout1.setOrientation(LinearLayout.VERTICAL);
answerText.setText("0");
calcButton.setText("Press to Multiply");
calcButton.setOnClickListener((android.view.View.OnClickListener) multiply);
layout1.addView(number1text);
layout1.addView(number2text);
layout1.addView(calcButton);
layout1.addView(answerText);
setContentView(layout1);
}
private OnClickListener multiply = new OnClickListener() {
@Override
public void onClick (View v){
String firstString = number1text.getText().toString();
String secondString = number2text.getText().toString();
double firstNumber = Double.parseDouble(firstString);
double secondNumber = Double.parseDouble(secondString);
double result = firstNumber * secondNumber;
String resultString = String.valueOf(result);
answerText.setText(resultString);
}
};
}
登录猫代码:
08-21 05:08:45.528: D/AndroidRuntime(809): Shutting down VM
08-21 05:08:45.528: W/dalvikvm(809): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-21 05:08:45.587: E/AndroidRuntime(809): FATAL EXCEPTION: main
08-21 05:08:45.587: E/AndroidRuntime(809): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firstprogram/com.firstprogram.MainActivity}: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.os.Looper.loop(Looper.java:137)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 05:08:45.587: E/AndroidRuntime(809): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 05:08:45.587: E/AndroidRuntime(809): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 05:08:45.587: E/AndroidRuntime(809): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 05:08:45.587: E/AndroidRuntime(809): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 05:08:45.587: E/AndroidRuntime(809): at dalvik.system.NativeStart.main(Native Method)
08-21 05:08:45.587: E/AndroidRuntime(809): Caused by: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 05:08:45.587: E/AndroidRuntime(809): at com.firstprogram.MainActivity.onCreate(MainActivity.java:37)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.Activity.performCreate(Activity.java:5133)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 05:08:45.587: E/AndroidRuntime(809): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 05:08:45.587: E/AndroidRuntime(809): ... 11 more
08-21 05:08:45.823: D/dalvikvm(809): GC_FOR_ALLOC freed 278K, 16% free 2739K/3240K, paused 61ms, total 94ms
08-21 05:10:27.568: D/AndroidRuntime(860): Shutting down VM
08-21 05:10:27.568: W/dalvikvm(860): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-21 05:10:27.615: E/AndroidRuntime(860): FATAL EXCEPTION: main
08-21 05:10:27.615: E/AndroidRuntime(860): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firstprogram/com.firstprogram.MainActivity}: java.lang.NullPointerException
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.os.Looper.loop(Looper.java:137)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 05:10:27.615: E/AndroidRuntime(860): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 05:10:27.615: E/AndroidRuntime(860): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 05:10:27.615: E/AndroidRuntime(860): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 05:10:27.615: E/AndroidRuntime(860): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 05:10:27.615: E/AndroidRuntime(860): at dalvik.system.NativeStart.main(Native Method)
08-21 05:10:27.615: E/AndroidRuntime(860): Caused by: java.lang.NullPointerException
08-21 05:10:27.615: E/AndroidRuntime(860): at android.view.ViewGroup.addViewInner(ViewGroup.java:3505)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.view.ViewGroup.addView(ViewGroup.java:3377)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.view.ViewGroup.addView(ViewGroup.java:3353)
08-21 05:10:27.615: E/AndroidRuntime(860): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:286)
08-21 05:10:27.615: E/AndroidRuntime(860): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:276)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.Activity.setContentView(Activity.java:1915)
08-21 05:10:27.615: E/AndroidRuntime(860): at com.firstprogram.MainActivity.onCreate(MainActivity.java:24)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.Activity.performCreate(Activity.java:5133)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 05:10:27.615: E/AndroidRuntime(860): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 05:10:27.615: E/AndroidRuntime(860): ... 11 more
08-21 05:11:37.875: D/AndroidRuntime(907): Shutting down VM
08-21 05:11:37.875: W/dalvikvm(907): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-21 05:11:38.155: E/AndroidRuntime(907): FATAL EXCEPTION: main
08-21 05:11:38.155: E/AndroidRuntime(907): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firstprogram/com.firstprogram.MainActivity}: java.lang.NullPointerException
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.os.Looper.loop(Looper.java:137)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 05:11:38.155: E/AndroidRuntime(907): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 05:11:38.155: E/AndroidRuntime(907): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 05:11:38.155: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 05:11:38.155: E/AndroidRuntime(907): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 05:11:38.155: E/AndroidRuntime(907): at dalvik.system.NativeStart.main(Native Method)
08-21 05:11:38.155: E/AndroidRuntime(907): Caused by: java.lang.NullPointerException
08-21 05:11:38.155: E/AndroidRuntime(907): at android.view.ViewGroup.addViewInner(ViewGroup.java:3505)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.view.ViewGroup.addView(ViewGroup.java:3377)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.view.ViewGroup.addView(ViewGroup.java:3353)
08-21 05:11:38.155: E/AndroidRuntime(907): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:286)
08-21 05:11:38.155: E/AndroidRuntime(907): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:276)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.Activity.setContentView(Activity.java:1915)
08-21 05:11:38.155: E/AndroidRuntime(907): at com.firstprogram.MainActivity.onCreate(MainActivity.java:23)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.Activity.performCreate(Activity.java:5133)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 05:11:38.155: E/AndroidRuntime(907): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 05:11:38.155: E/AndroidRuntime(907): ... 11 more
08-21 05:53:02.416: D/AndroidRuntime(971): Shutting down VM
08-21 05:53:02.416: W/dalvikvm(971): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-21 05:53:02.469: E/AndroidRuntime(971): FATAL EXCEPTION: main
08-21 05:53:02.469: E/AndroidRuntime(971): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firstprogram/com.firstprogram.MainActivity}: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.os.Looper.loop(Looper.java:137)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 05:53:02.469: E/AndroidRuntime(971): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 05:53:02.469: E/AndroidRuntime(971): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 05:53:02.469: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 05:53:02.469: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 05:53:02.469: E/AndroidRuntime(971): at dalvik.system.NativeStart.main(Native Method)
08-21 05:53:02.469: E/AndroidRuntime(971): Caused by: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 05:53:02.469: E/AndroidRuntime(971): at com.firstprogram.MainActivity.onCreate(MainActivity.java:36)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.Activity.performCreate(Activity.java:5133)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 05:53:02.469: E/AndroidRuntime(971): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 05:53:02.469: E/AndroidRuntime(971): ... 11 more
08-21 06:00:07.957: D/AndroidRuntime(1010): Shutting down VM
08-21 06:00:08.016: W/dalvikvm(1010): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-21 06:00:08.055: E/AndroidRuntime(1010): FATAL EXCEPTION: main
08-21 06:00:08.055: E/AndroidRuntime(1010): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firstprogram/com.firstprogram.MainActivity}: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.os.Looper.loop(Looper.java:137)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-21 06:00:08.055: E/AndroidRuntime(1010): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 06:00:08.055: E/AndroidRuntime(1010): at java.lang.reflect.Method.invoke(Method.java:525)
08-21 06:00:08.055: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-21 06:00:08.055: E/AndroidRuntime(1010): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-21 06:00:08.055: E/AndroidRuntime(1010): at dalvik.system.NativeStart.main(Native Method)
08-21 06:00:08.055: E/AndroidRuntime(1010): Caused by: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
08-21 06:00:08.055: E/AndroidRuntime(1010): at com.firstprogram.MainActivity.onCreate(MainActivity.java:36)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.Activity.performCreate(Activity.java:5133)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-21 06:00:08.055: E/AndroidRuntime(1010): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-21 06:00:08.055: E/AndroidRuntime(1010): ... 11 more
最佳答案
logcat 中有趣的一行是:
Caused by: java.lang.ClassCastException: com.firstprogram.MainActivity$1 cannot be cast to android.view.View$OnClickListener
Android 框架中有多个 OnClickListener
定义,看来您没有使用正确的定义。
如果你想使用View.OnClickListener
那么你应该使用:
private View.OnClickListener multiply = new View.OnClickListener() {
....
}
关于java - "Unfortunately your app has stopped"模拟器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18354129/
我使用 iOS 4.2 和 Xcode 3.2.5 创建了一个通用二进制文件。我正在尝试对应用程序进行一些自动化测试,由于 iPad 和 iPhone 版本之间的界面略有不同,因此我有单独的 UIAu
这是一个概念性的问题。如果有人能澄清背后的故事,那就太好了。 我了解模拟器和模拟器之间的区别。 模拟器:模仿设备环境(硬件、网络功能等)。与设备相比,我们更有可能得到非常接近的结果。 模拟器:使用正在
是否有任何现成的解决方案可以模拟或模拟 LDAP 服务器功能? 或者是否可以在 ubuntu 上安装 ldap 服务器(仅适用于 localhost)? 如果它不是来自 localhost 的 jsu
我正在将我的应用程序修复为通用二进制文件。模拟器上的测试似乎默认使用 iPad。对于诸如检查方向和小型 UI 更新之类的小修正,我能找到的获取 iPhone 版本的唯一方法是插入我的 iPhone 并
Emulator: emulator: WARNING: Could not connect to proxy at ::1:8080: Unknown error ! - Android 将 And
我的应用程序在 ios 4.3 模拟器中运行良好,但在 ios 5 模拟器中运行不佳。我的 iPhone 上有 ios 5,我的应用程序确实可以在 iPhone 上运行。 该应用在所有这三种环境中都可
我在 azure 上制作了移动应用程序,并将其快速启动为 xamarian.forms,并且(在未能发布下载的表 api 应用程序并决定在浏览器中编辑它之后)下载了他们提供的客户端应用程序。然后,当我
Emulator: emulator: ERROR: x86 emulation currently requires hardware acceleration! Emulator: Process
我试图在 iOS 10.3 模拟器上将任意文件从我的应用程序的沙箱保存到 iCloud Drive。 iCloud Drive 已启用并且我已登录。如果我在模拟器上打开 iCloud Drive 应用
有谁知道一个小型、快速、支持 DOM 层的 javascript 模拟器?在 C/C++ 中? 问题:我需要在爬虫应用程序中对 javascript 的基本支持,并且想知道除了以下选项之外是否还有其他
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
我是 Xcode 开发新手。我在基于 Lion 的 Mac 上安装了 Xcode 4.3.1,并取消设置 ~/Library 上的隐藏标志。 我在这里读到了有关 iPhone/iPad 模拟器的信息
我已在 VisualStudio 2015 AZURE SDK 2.9、C# 中创建辅助角色 我在每个方法的开头添加了断点: public override void Run() {
全部。我已经安装了 Azure SDK 1.7。解决方案中的所有程序集都是使用“任何 CPU”设置进行编译的。但是当我在我的计算机上的 Azure 模拟器中启动解决方案时,其中之一失败了。该错误非常奇
有没有独立的 WAP 模拟器来模拟诺基亚 6600 和索尼爱立信 MIDP 手机的 waop 网站? 我正在创建一个 WAP 门户,我不想每次都将所有文件上传到网络上,然后将其加载到 Opera Mi
我已经安装了 Tizen 的 Visual Studio Code 扩展,并且(看起来)进展顺利。 但是,当我启动 Tizen 模拟器管理器时,我没有安装任何平台,并且当我尝试安装平台时,没有可用的平
我目前正在我的 jquery mobile/phonegap 应用程序中处理表单。在此表单中,我有两个选择列表。它们在我的桌面浏览器(firefox、safari、chrome)中都能正常工作。 奇怪
我尝试制作一个分辨率为 480x480 像素的模拟器。但是模拟器永远不会完成启动。它卡在 Android Logo 页面上。分辨率有限制吗? 最佳答案 模拟器 is not smart about s
我不知道如何在虚拟设备上启用快照功能。该选项是灰色的,创建或编辑虚拟设备时没有设置。我使用的是最新版本的 SDK 工具修订版 22.6.3 这是我的窗口的样子:Create new Android V
我正在尝试使用具有特定屏幕分辨率的模拟器,但是当我将屏幕参数设置为我需要的参数时,键盘消失了。这样我就没有后退按钮,主页按钮..任何想法如何解决这个问题?这是我在 AVD 管理器中设置的:屏幕分辨率:
我是一名优秀的程序员,十分优秀!