- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想创建一个音板,所以当你点击按钮时它会播放声音。
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.akali);
Button b = (Button) findViewById(R.id.akaliJokeButton);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
MediaPlayer mp = MediaPlayer.create(Akali.this, R.raw.akalijoke);
mp.start();
}
});
}
这是我目前拥有的代码。但是我得到一个无指针异常错误
07-25 14:36:47.919: DEBUG/AndroidRuntime(1079): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-25 14:36:47.919: DEBUG/AndroidRuntime(1079): CheckJNI is ON
07-25 14:36:48.529: DEBUG/AndroidRuntime(1079): Calling main entry com.android.commands.pm.Pm
07-25 14:36:48.560: DEBUG/AndroidRuntime(1079): Shutting down VM
07-25 14:36:48.569: DEBUG/dalvikvm(1079): GC_CONCURRENT freed 101K, 71% free 297K/1024K, external 0K/0K, paused 1ms+1ms
07-25 14:36:48.579: DEBUG/dalvikvm(1079): Debugger has detached; object registry had 1 entries
07-25 14:36:48.599: INFO/dalvikvm(1079): JNI: AttachCurrentThread (from ???.???)
07-25 14:36:48.599: INFO/AndroidRuntime(1079): NOTE: attach of thread 'Binder Thread #3' failed
07-25 14:36:48.989: DEBUG/AndroidRuntime(1089): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
07-25 14:36:48.989: DEBUG/AndroidRuntime(1089): CheckJNI is ON
07-25 14:36:49.579: DEBUG/AndroidRuntime(1089): Calling main entry com.android.commands.am.Am
07-25 14:36:49.609: INFO/ActivityManager(61): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.reg.lolsoundboard/.Main } from pid 1089
07-25 14:36:49.829: DEBUG/AndroidRuntime(1089): Shutting down VM
07-25 14:36:49.849: DEBUG/dalvikvm(1089): GC_CONCURRENT freed 102K, 69% free 320K/1024K, external 0K/0K, paused 1ms+1ms
07-25 14:36:49.849: DEBUG/jdwp(1089): Got wake-up signal, bailing out of select
07-25 14:36:49.849: DEBUG/dalvikvm(1089): Debugger has detached; object registry had 1 entries
07-25 14:36:49.879: INFO/ActivityManager(61): Start proc com.reg.lolsoundboard for activity com.reg.lolsoundboard/.Main: pid=1099 uid=10036 gids={}
07-25 14:36:49.931: INFO/AndroidRuntime(1089): NOTE: attach of thread 'Binder Thread #3' failed
07-25 14:36:50.839: DEBUG/dalvikvm(1099): GC_EXTERNAL_ALLOC freed 49K, 53% free 2557K/5379K, external 2002K/2137K, paused 54ms
07-25 14:36:51.250: INFO/ActivityManager(61): Displayed com.reg.lolsoundboard/.Main: +1s426ms (total +8m29s588ms)
07-25 14:36:52.179: INFO/ActivityManager(61): Starting: Intent { cmp=com.reg.lolsoundboard/.Akali } from pid 1099
07-25 14:36:52.299: DEBUG/AndroidRuntime(1099): Shutting down VM
07-25 14:36:52.299: WARN/dalvikvm(1099): threadid=1: thread exiting with uncaught exception (group=0x40015560)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): FATAL EXCEPTION: main
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reg.lolsoundboard/com.reg.lolsoundboard.Akali}: java.lang.NullPointerException
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.os.Looper.loop(Looper.java:123)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at java.lang.reflect.Method.invoke(Method.java:507)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at dalvik.system.NativeStart.main(Native Method)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): Caused by: java.lang.NullPointerException
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at com.reg.lolsoundboard.Akali.onCreate(Akali.java:19)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
07-25 14:36:52.309: ERROR/AndroidRuntime(1099): ... 11 more
07-25 14:36:52.319: WARN/ActivityManager(61): Force finishing activity com.reg.lolsoundboard/.Akali
07-25 14:36:52.329: WARN/ActivityManager(61): Force finishing activity com.reg.lolsoundboard/.Main
07-25 14:36:52.839: WARN/ActivityManager(61): Activity pause timeout for HistoryRecord{406fa098 com.reg.lolsoundboard/.Akali}
07-25 14:36:54.199: INFO/Process(1099): Sending signal. PID: 1099 SIG: 9
07-25 14:36:54.209: INFO/ActivityManager(61): Process com.reg.lolsoundboard (pid 1099) has died.
07-25 14:36:54.209: INFO/WindowManager(61): WIN DEATH: Window{40761880 com.reg.lolsoundboard/com.reg.lolsoundboard.Main paused=true}
07-25 14:36:54.299: WARN/InputManagerService(61): Got RemoteException sending setActive(false) notification to pid 1099 uid 10036
XML文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/akalibg" android:weightSum="1">
<RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:layout_height="wrap_content" android:layout_weight="0.33">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:id="@+id/akaliLaugh1" android:text="Laugh 1"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:text="Laugh 2" android:id="@+id/akaliLaugh2"></Button>
<Button android:text="Laugh 3" android:id="@+id/akaliLaugh3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignTop="@+id/akaliLaugh4" android:layout_alignLeft="@+id/akaliJokeButton"></Button>
<Button android:id="@+id/akaliLaugh4" android:layout_height="wrap_content" android:keepScreenOn="false" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignLeft="@+id/akaliLaugh1" android:text="Laugh 4"></Button>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignBottom="@+id/akaliLaugh4" android:layout_alignParentRight="true" android:id="@+id/akaliTaunt" android:layout_alignLeft="@+id/akaliLaugh2" android:text="Taunt 1"></Button>
<Button android:id="@+id/button1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignRight="@+id/akaliLaugh3" android:text="Joke 1"></Button>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout2" android:layout_height="wrap_content">
</RelativeLayout>
</LinearLayout>
进入实际音板的初始主屏幕
package com.reg.lolsoundboard;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton b = (ImageButton) findViewById(R.id.akaliButton);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
startActivity(new Intent(Main.this, Akali.class));
}
});
}
}
最佳答案
您似乎没有 ID 为“akaliJokeButton”的按钮
关于java - Android SDK 空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6817731/
问题很简单:我正在寻找一种优雅的使用方式 CompletableFuture#exceptionally与 CompletableFuture#supplyAsync 一起.这是行不通的: priva
对于 Web 服务,我们通常使用 maven-jaxb2-plugin 生成 java bean,并在 Spring 中使用 JAXB2 编码。我想知道如何处理 WSDL/XSD 中声明的(SOAP-
这个问题已经有答案了: Array index out of bound behavior (10 个回答) 已关闭 8 年前。 我对下面的 C 代码感到好奇 int main(){
当在类的开头使用上下文和资源初始化 MediaPlayer 对象时,它会抛出 NullPointer 异常,但是当在类的开头声明它时(因此它是 null),然后以相同的方式初始化它在onCreate方
嘿 我尝试将 java 程序连接到 REST API。 使用相同的代码部分,我在 Java 6 中遇到了 Java 异常,并且在 Java 8 中运行良好。 环境相同: 信任 机器 unix 用户 代
我正在尝试使用 Flume 和 Hive 进行 Twitter 分析。为了从 twitter 获取推文,我在 flume.conf 文件中设置了所有必需的参数(consumerKey、consumer
我在 JavaFX 异常方面遇到一些问题。我的项目在我的 Eclipse 中运行,但现在我的 friend 也尝试访问该项目。我们已共享并直接保存到保管箱文件夹中。但他根本无法让它发挥作用。他在控制台
假设我使用 blur() 事件验证了电子邮件 ID,我正在这样做: $('#email').blur(function(){ //make ajax call , check if dupli
我这样做是为了从 C 代码调用非托管函数。 pCallback 是一个函数指针,因此在托管端是一个委托(delegate)。 [DllImport("MyDLL.dll")] public stati
为什么这段代码是正确的: try { } catch(ArrayOutOfBoundsException e) {} 这是错误的: try { } catch(IOException e) {} 这段
我遇到了以下问题:有导出函数的DLL。 代码示例如下:[动态链接库] __declspec(dllexport) int openDevice(int,void**) [应用] 开发者.h: __de
从其他线程,我知道我们不应该在析构函数中抛出异常!但是对于下面的例子,它确实有效。这是否意味着我们只能在一个实例的析构函数中抛出异常?我们应该如何理解这个代码示例! #include using n
为什么需要异常 引出 public static void main(String[
1. Java的异常机制 Throwable类是Java异常类型的顶层父类,一个对象只有是 Throwable 类的(直接或者间接)实例,他才是一个异常对象,才能被异常处理机制识别。JDK中内
我是 Python 的新手,我对某种异常方法的实现有疑问。这是代码(缩写): class OurException(Exception): """User defined Exception"
我已经创建了以下模式来表示用户和一组线程之间的关联,这些线程按他们的最后一条消息排序(用户已经阅读了哪些线程,哪些没有): CREATE TABLE table(user_id bigint, mes
我正在使用 Python 编写一个简单的自动化脚本,它可能会在多个位置引发异常。在他们每个人中,我都想记录一条特定的消息并退出程序。为此,我在捕获异常并处理它(执行特定的日志记录操作等)后引发 Sys
谁能解释一下为什么这会导致错误: let xs = [| "Mary"; "Mungo"; "Midge" |] Array.iter printfn xs 虽然不是这样: Array.iter pr
在我使用 Play! 的网站上,我有一个管理部分。所有 Admin Controller 都有一个 @With 和一个 @Check 注释。 断开连接后,一切正常。连接后,每次加载页面(任何页面,无论
我尝试连接到 azure 表存储并添加一个对象。它在本地主机上工作得很好,但是在我使用的服务器上我得到以下异常及其内部异常: Exception of type 'Microsoft.Wind
我是一名优秀的程序员,十分优秀!