1

我根据项目首先 home.java 运行和 play.java 运行创建了两个类文件 home.java 和 play.java,我在 Play.java 中声明并编写方法我需要在 Home.java 中调用该方法

主页.java

Public void onItemClick()
 {.............
  ..............
  p1.pl(songindex)//p1 is the object for Play.java
   .......
   } 

播放.java

public void pl(int songindex)
{
if(songindex==0)
{
 .....
 .....
 }
 else(songindex==1)
 {
 ......
 ......
 }
}

我在模拟器中尝试了这段代码“不幸的是应用程序关闭”错误

日志猫:

04-10 10:44:05.571: I/ActivityManager(879): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.bostonmediatech.gayatrimantra/.Main} from pid 1015 
04-10 10:44:05.571: W/WindowManager(879): Failure taking screenshot for (180x300) to layer 21005 
04-10 10:44:05.571: D/dalvikvm(1449): Not late-enabling CheckJNI (already on) 
04-10 10:44:05.571: I/ActivityManager(879): Start proc com.bostonmediatech.gayatrimantra for activity com.bostonmediatech.gayatrimantra/.Main: pid=1449 uid=10031 gids={} 
04-10 10:44:05.579: D/dalvikvm(1449): GC_FOR_ALLOC freed 62K, 3% free 9021K/9283K, paused 0ms 
04-10 10:44:05.579: I/dalvikvm-heap(1449): Grow heap (frag case) to 9.450MB for 614412-byte allocation 
04-10 10:44:05.589: W/NetworkManagementSocketTagger(879): setKernelCountSet(10031, 1) failed with errno -2 
04-10 10:44:05.609: D/dalvikvm(1449): GC_CONCURRENT freed 0K, 4% free 9621K/9927K, paused 0ms+0ms 
04-10 10:44:05.671: D/gralloc_goldfish(1449): Emulator without GPU emulation detected. 
04-10 10:44:05.719: I/ActivityManager(879): Displayed com.bostonmediatech.gayatrimantra/.Main: +154ms (total +35s954ms) 
04-10 10:44:05.719: W/InputManagerService(879): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@b5b5f210 (uid=10005 pid=1015) 
04-10 10:44:06.299: W/NetworkManagementSocketTagger(879): setKernelCountSet(10005, 0) failed with errno -2 
04-10 10:44:07.760: I/ActivityManager(879): START {act=com.bostonmediatech.gayatrimantra.CLEARSCREEN cmp=com.bostonmediatech.gayatrimantra/.Home} from pid 1449 
04-10 10:44:07.760: W/WindowManager(879): Failure taking screenshot for (180x300) to layer 21010 
04-10 10:44:07.770: D/dalvikvm(1449): GC_FOR_ALLOC freed 6K, 3% free 9641K/9927K, paused 3ms 
04-10 10:44:07.770: I/dalvikvm-heap(1449): Grow heap (frag case) to 10.055MB for 614412-byte allocation 
04-10 10:44:07.789: D/dalvikvm(1449): GC_CONCURRENT freed <1K, 4% free 10241K/10567K, paused 0ms+0ms 
04-10 10:44:07.820: I/ActivityManager(879): Displayed com.bostonmediatech.gayatrimantra/.Home: +60ms 
04-10 10:44:09.499: I/ActivityManager(879): START {cmp=com.bostonmediatech.gayatrimantra/.Play} from pid 1449 
04-10 10:44:09.499: W/WindowManager(879): Failure taking screenshot for (180x300) to layer 21010 
04-10 10:44:09.499: D/AndroidRuntime(1449): Shutting down VM 
04-10 10:44:09.499: W/dalvikvm(1449): threadid=1: thread exiting with uncaught exception (group=0xb512a180) 
04-10 10:44:09.499: E/AndroidRuntime(1449): FATAL EXCEPTION: main 
04-10 10:44:09.499: E/AndroidRuntime(1449): java.lang.NullPointerException 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.content.ContextWrapper.getResources(ContextWrapper.java:81) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.media.MediaPlayer.create(MediaPlayer.java:731) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at com.bostonmediatech.gayatrimantra.Play.pl(Play.java:64) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at com.bostonmediatech.gayatrimantra.Home.onItemClick(Home.java:82) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.widget.AdapterView.performItemClick(AdapterView.java:292) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.widget.AbsListView.performItemClick(AbsListView.java:1058) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.widget.AbsListView$1.run(AbsListView.java:3168) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.os.Handler.handleCallback(Handler.java:605) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.os.Handler.dispatchMessage(Handler.java:92) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.os.Looper.loop(Looper.java:137) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at java.lang.reflect.Method.invokeNative(Native Method) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at java.lang.reflect.Method.invoke(Method.java:511) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-10 10:44:09.499: E/AndroidRuntime(1449):     at dalvik.system.NativeStart.main(Native Method) 
04-10 10:44:10.009: W/ActivityManager(879): Activity pause timeout for ActivityRecord{b5bc2848 com.bostonmediatech.gayatrimantra/.Home} 
04-10 10:44:10.009: I/Process(879): Sending signal. PID: 1449 SIG: 3 
04-10 10:44:10.019: I/dalvikvm(1449): threadid=3: reacting to signal 3 
04-10 10:44:10.019: I/dalvikvm(1449): Wrote stack traces to '/data/anr/traces.txt' 
04-10 10:44:10.551: I/Process(879): Sending signal. PID: 1449 SIG: 3 
04-10 10:44:10.551: I/dalvikvm(1449): threadid=3: reacting to signal 3 
04-10 10:44:10.551: I/dalvikvm(1449): Wrote stack traces to '/data/anr/traces.txt' 
04-10 10:44:11.069: I/Process(879): Sending signal. PID: 1449 SIG: 3 
04-10 10:44:11.069: I/dalvikvm(1449): threadid=3: reacting to signal 3 
04-10 10:44:11.069: I/dalvikvm(1449): Wrote stack traces to '/data/anr/traces.txt' 
04-10 10:44:11.559: I/Process(879): Sending signal. PID: 1449 SIG: 3 
04-10 10:44:11.559: I/dalvikvm(1449): threadid=3: reacting to signal 3 
04-10 10:44:11.559: I/dalvikvm(1449): Wrote stack traces to '/data/anr/traces.txt' 
04-10 10:44:12.021: I/Process(1449): Sending signal. PID: 1449 SIG: 9 
04-10 10:44:12.021: I/ActivityManager(879): Process com.bostonmediatech.gayatrimantra (pid 1449) has died. 
04-10 10:44:12.021: I/WindowManager(879): WIN DEATH: Window{b5cd5088 com.bostonmediatech.gayatrimantra/com.bostonmediatech.gayatrimantra.Home paused=false} 
04-10 10:44:12.021: W/ActivityManager(879): Force removing ActivityRecord{b5c8e9a8 com.bostonmediatech.gayatrimantra/.Play}: app died, no saved state 
04-10 10:44:12.021: W/NetworkManagementSocketTagger(879): setKernelCountSet(10031, 0) failed with errno -2 
04-10 10:44:12.021: W/ActivityManager(879): Force removing ActivityRecord{b5bc2848 com.bostonmediatech.gayatrimantra/.Home}: app died, no saved state 
04-10 10:44:12.029: W/NetworkManagementSocketTagger(879): setKernelCountSet(10005, 1) failed with errno -2 
04-10 10:44:12.129: D/dalvikvm(1015): GC_FOR_ALLOC freed 3001K, 19% free 17672K/21703K, paused 3ms 
04-10 10:44:12.170: W/InputManagerService(879): Got RemoteException sending setActive(false) notification to pid 1449 uid 10031 
04-10 10:44:12.312: D/dalvikvm(1015): GC_CONCURRENT freed 1724K, 18% free 17955K/21703K, paused 0ms+1ms 
04-10 10:44:12.321: D/dalvikvm(1015): GC_FOR_ALLOC freed 52K, 18% free 17989K/21703K, paused 5ms 
04-10 10:44:12.321: I/dalvikvm-heap(1015): Grow heap (frag case) to 18.845MB for 1286220-byte allocation 
04-10 10:44:12.365: D/dalvikvm(1015): GC_FOR_ALLOC freed 1K, 17% free 19244K/22983K, paused 18ms 
04-10 10:44:21.721: D/dalvikvm(1003): GC_CONCURRENT freed 381K, 5% free 9494K/9991K, paused 1ms+0ms 
04-10 10:44:42.850: W/ThrottleService(879): unable to find stats for iface rmnet0 
4

1 回答 1

0

没有太多代码,但我猜你忘记初始化 p1 你可能已经给出的空指针异常, Play p1而不是 Play p1 = new Play();

于 2013-04-10T05:28:57.533 回答