没有调用一个函数?

时间:2015-08-03 11:46:59

标签: java android eclipse

我试图调用我的两个函数activateVibration(),playRingTone()。 但是,当我启动我的应用程序时,它引发了错误"抱歉,应用程序已停止运行"。 这是我的Profile.java文件

@Override
public boolean onContextItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){

    case 0:
        if(item.getTitle()=="buddy"){
    General myGeneral =new General();
        myGeneral.activateVibration();
    myGeneral.playRingtone();
        }
        return true;
}

这是我的General.java

public class General

    {

        Context mcontext;
        private AudioManager audi  = null;


        public  void activateVibration() {
            // Here i am getting error in Audio_Service
            audi = (AudioManager) mcontext.getSystemService(Context.AUDIO_SERVICE);

                audi.setRingerMode(AudioManager.RINGER_MODE_NORMAL);

                }

        public void playRingtone() {
            // TODO Auto-generated method stub




            Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
            Ringtone ring = RingtoneManager.getRingtone(mcontext.getApplicationContext(), alert);
            //Ringtone ring = RingtoneManager.getRingtone(this, alert);
            ring.setStreamType(AudioManager.STREAM_RING);
            ring.play();


        }


    }   

这是logcat文件

08-03 17:14:19.662: D/libEGL(23933): loaded /system/lib/egl/libGLES_hawaii.so
08-03 17:14:19.742: D/(23933): mem_init ++
08-03 17:14:19.742: D/(23933): gHwMemAllocator client 3
08-03 17:14:19.742: D/(23933): **** Using ION allocator ****
08-03 17:14:19.742: D/(23933): registered SIGUSR1[10] for pid[23933]
08-03 17:14:19.742: D/(23933): HwMemAllocatorImpl Static Counters 0 0
08-03 17:14:19.742: D/(23933): HwMemAllocatorImpl[4fd9ddcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
08-03 17:14:19.772: D/(23933): mem_init 4fd9ddcc--
08-03 17:14:19.772: D/ION(23933): config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
08-03 17:14:19.812: D/MM_DEVICE(23933): Waiting for mm thread to come up
08-03 17:14:19.812: D/MM_DEVICE(23933): mm_device_thread starting
08-03 17:14:19.882: D/HAWAII_EGL(23933): eglCreateContext() config: 18 context: 0x513ebab8, VC context 1, Thread 23933
08-03 17:14:19.892: D/HAWAII_EGL(23933): Set SWAP INTERVAL 0
08-03 17:14:19.892: D/HAWAII_EGL(23933): eglCreateWindowSurface() surface: 0x513ebad8, VC surface: 1, Thread: 23933
08-03 17:14:19.892: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x513ebad8, 0x513ebad8) Thread: 23933
08-03 17:14:19.902: D/OpenGLRenderer(23933): Enabling debug mode 0
08-03 17:14:20.523: I/Choreographer(23933): Skipped 33 frames!  The application may be doing too much work on its main thread.
08-03 17:14:22.225: I/Choreographer(23933): Skipped 32 frames!  The application may be doing too much work on its main thread.
08-03 17:14:23.025: D/AbsListView(23933): Get MotionRecognitionManager
08-03 17:14:23.115: D/AbsListView(23933): onVisibilityChanged() is called, visibility : 4
08-03 17:14:23.115: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:23.136: D/AbsListView(23933): onVisibilityChanged() is called, visibility : 0
08-03 17:14:23.136: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:23.226: D/HAWAII_EGL(23933): Set SWAP INTERVAL 0
08-03 17:14:23.226: D/HAWAII_EGL(23933): eglCreateWindowSurface() surface: 0x514db608, VC surface: 2, Thread: 23933
08-03 17:14:23.226: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x514db608, 0x514db608) Thread: 23933
08-03 17:14:23.226: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:23.226: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x513ebad8, 0x513ebad8) Thread: 23933
08-03 17:14:23.236: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x514db608, 0x514db608) Thread: 23933
08-03 17:14:23.276: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:23.276: D/WritingBuddyImpl(23933): getCurrentWritingBuddyView() 
08-03 17:14:23.346: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:24.627: D/AbsListView(23933): Get MotionRecognitionManager
08-03 17:14:25.338: I/Choreographer(23933): Skipped 52 frames!  The application may be doing too much work on its main thread.
08-03 17:14:25.388: D/HAWAII_EGL(23933): Set SWAP INTERVAL 0
08-03 17:14:25.398: D/HAWAII_EGL(23933): eglCreateWindowSurface() surface: 0x514f22c8, VC surface: 3, Thread: 23933
08-03 17:14:25.398: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x514f22c8, 0x514f22c8) Thread: 23933
08-03 17:14:25.408: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:25.418: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:25.418: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x514db608, 0x514db608) Thread: 23933
08-03 17:14:25.428: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:25.428: D/HAWAII_EGL(23933): eglMakeCurrent(0x513ebab8, 0x514f22c8, 0x514f22c8) Thread: 23933
08-03 17:14:25.528: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:25.548: D/AbsListView(23933): unregisterIRListener() is called 
08-03 17:14:28.331: D/AndroidRuntime(23933): Shutting down VM
08-03 17:14:28.331: W/dalvikvm(23933): threadid=1: thread exiting with uncaught exception (group=0x419b3930)
08-03 17:14:28.491: E/AndroidRuntime(23933): FATAL EXCEPTION: main
08-03 17:14:28.491: E/AndroidRuntime(23933): java.lang.NullPointerException
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.haider.first.General.playRingtone(General.java:36)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.haider.first.Profile.onContextItemSelected(Profile.java:71)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.app.Activity.onMenuItemSelected(Activity.java:2630)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.policy.impl.PhoneWindow$DialogMenuCallback.onMenuItemSelected(PhoneWindow.java:4460)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:201)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:979)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.widget.AdapterView.performItemClick(AdapterView.java:301)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.widget.AbsListView.performItemClick(AbsListView.java:1507)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3292)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.widget.AbsListView$1.run(AbsListView.java:4545)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.os.Handler.handleCallback(Handler.java:725)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.os.Handler.dispatchMessage(Handler.java:92)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.os.Looper.loop(Looper.java:176)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at android.app.ActivityThread.main(ActivityThread.java:5317)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at java.lang.reflect.Method.invokeNative(Native Method)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at java.lang.reflect.Method.invoke(Method.java:511)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-03 17:14:28.491: E/AndroidRuntime(23933):    at dalvik.system.NativeStart.main(Native Method)
08-03 17:14:35.988: D/libEGL(23989): loaded /system/lib/egl/libGLES_hawaii.so
08-03 17:14:36.008: D/(23989): mem_init ++
08-03 17:14:36.008: D/(23989): gHwMemAllocator client 3
08-03 17:14:36.008: D/(23989): **** Using ION allocator ****
08-03 17:14:36.008: D/(23989): registered SIGUSR1[10] for pid[23989]
08-03 17:14:36.008: D/(23989): HwMemAllocatorImpl Static Counters 0 0
08-03 17:14:36.008: D/(23989): HwMemAllocatorImpl[4fd9ddcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
08-03 17:14:36.018: D/(23989): mem_init 4fd9ddcc--
08-03 17:14:36.018: D/ION(23989): config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
08-03 17:14:36.028: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.028: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): Waiting for mm thread to come up
08-03 17:14:36.038: D/MM_DEVICE(23989): mm_device_thread starting
08-03 17:14:36.048: D/HAWAII_EGL(23989): eglCreateContext() config: 18 context: 0x514d2ec0, VC context 1, Thread 23989
08-03 17:14:36.048: D/HAWAII_EGL(23989): Set SWAP INTERVAL 0
08-03 17:14:36.058: D/HAWAII_EGL(23989): eglCreateWindowSurface() surface: 0x514d2f08, VC surface: 1, Thread: 23989
08-03 17:14:36.058: D/HAWAII_EGL(23989): eglMakeCurrent(0x514d2ec0, 0x514d2f08, 0x514d2f08) Thread: 23989
08-03 17:14:36.058: D/OpenGLRenderer(23989): Enabling debug mode 0

0 个答案:

没有答案