RUn TIme Exception error

时间:2015-07-31 19:45:14

标签: java android

I am trying to caal my Utill.java class from my Profile.java class. But here ia m facing issue on run time. I am getting error of unable to find activity compmonent. This is my code file. Profile.java

public class Profile extends ListActivity implements OnItemLongClickListener{


        //creating context menu
                @Override
                public void onCreateContextMenu(ContextMenu menu, View v,
                        ContextMenuInfo menuInfo) {
                    // TODO Auto-generated method stub
                    super.onCreateContextMenu(menu, v, menuInfo);
                    MenuInflater inflater = getMenuInflater();
                    inflater.inflate(R.menu.context_menu, menu);

                    }


        // creating context item    

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

                    case R.id.item1:
    //calling vibration method from here
                        startActivity(new Intent(Profile.this,Util.class));
                        return true;


                    case R.id.item2 :
                        startActivity(new Intent(Profile.this,Custom.class));

                        return true;
                    default:
                    return super.onContextItemSelected(item);
                    }




                }


            }

Utill.java

  public class Util extends Activity{

        private AudioManager audi = null;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);


            audi = (AudioManager) getSystemService(AUDIO_SERVICE);
//creating object to call methods           
Util mytest = new Util();
            mytest.activateVibration(); // calling method
            activateVibration();


        }
    //Method for activate vibration
        private void activateVibration() {
            // TODO Auto-generated method stub

                audi.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                }


    }

This is my logcat file

08-01 00:55:07.122: D/libEGL(26849): loaded /system/lib/egl/libGLES_hawaii.so
08-01 00:55:07.122: D/(26849): mem_init ++
08-01 00:55:07.122: D/(26849): gHwMemAllocator client 3
08-01 00:55:07.122: D/(26849): **** Using ION allocator ****
08-01 00:55:07.122: D/(26849): registered SIGUSR1[10] for pid[26849]
08-01 00:55:07.122: D/(26849): HwMemAllocatorImpl Static Counters 0 0
08-01 00:55:07.122: D/(26849): HwMemAllocatorImpl[4fa2edcc] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
08-01 00:55:07.122: D/(26849): mem_init 4fa2edcc--
08-01 00:55:07.122: D/ION(26849): config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
08-01 00:55:07.142: D/MM_DEVICE(26849): Waiting for mm thread to come up
08-01 00:55:07.142: D/MM_DEVICE(26849): mm_device_thread starting
08-01 00:55:07.152: D/HAWAII_EGL(26849): eglCreateContext() config: 18 context: 0x4fc28fa8, VC context 1, Thread 26849
08-01 00:55:07.152: D/HAWAII_EGL(26849): Set SWAP INTERVAL 0
08-01 00:55:07.162: D/HAWAII_EGL(26849): eglCreateWindowSurface() surface: 0x4fc28fc8, VC surface: 1, Thread: 26849
08-01 00:55:07.162: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x4fc28fc8, 0x4fc28fc8) Thread: 26849
08-01 00:55:07.162: D/OpenGLRenderer(26849): Enabling debug mode 0
08-01 00:55:08.233: D/AbsListView(26849): Get MotionRecognitionManager
08-01 00:55:08.253: D/AbsListView(26849): onVisibilityChanged() is called, visibility : 4
08-01 00:55:08.253: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:08.253: D/AbsListView(26849): onVisibilityChanged() is called, visibility : 0
08-01 00:55:08.253: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:08.273: D/HAWAII_EGL(26849): Set SWAP INTERVAL 0
08-01 00:55:08.273: D/HAWAII_EGL(26849): eglCreateWindowSurface() surface: 0x50672480, VC surface: 2, Thread: 26849
08-01 00:55:08.273: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x50672480, 0x50672480) Thread: 26849
08-01 00:55:08.273: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:08.273: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x4fc28fc8, 0x4fc28fc8) Thread: 26849
08-01 00:55:08.283: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x50672480, 0x50672480) Thread: 26849
08-01 00:55:08.293: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:08.293: D/WritingBuddyImpl(26849): getCurrentWritingBuddyView() 
08-01 00:55:08.343: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.174: D/AbsListView(26849): Get MotionRecognitionManager
08-01 00:55:09.254: D/HAWAII_EGL(26849): Set SWAP INTERVAL 0
08-01 00:55:09.254: D/HAWAII_EGL(26849): eglCreateWindowSurface() surface: 0x50541bf0, VC surface: 3, Thread: 26849
08-01 00:55:09.254: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x50541bf0, 0x50541bf0) Thread: 26849
08-01 00:55:09.264: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.264: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.274: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.284: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.294: D/AbsListView(26849): unregisterIRListener() is called 
08-01 00:55:09.474: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x50672480, 0x50672480) Thread: 26849
08-01 00:55:09.865: D/HAWAII_EGL(26849): eglMakeCurrent(0x4fc28fa8, 0x50541bf0, 0x50541bf0) Thread: 26849
08-01 00:55:09.985: D/HAWAII_EGL(26849): eglMakeCurrent(NULL) Thread: 26849
08-01 00:55:09.985: D/HAWAII_EGL(26849): eglDestroySurface() surface: 0x50541bf0, android window 0x500cd850, Thread: 26849
08-01 00:55:10.005: D/AbsListView(26849): onDetachedFromWindow
08-01 00:55:10.015: D/AndroidRuntime(26849): Shutting down VM
08-01 00:55:10.015: W/dalvikvm(26849): threadid=1: thread exiting with uncaught exception (group=0x41d7c930)
08-01 00:55:10.045: E/AndroidRuntime(26849): FATAL EXCEPTION: main
08-01 00:55:10.045: E/AndroidRuntime(26849): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.haider.first/com.haider.first.Util}: java.lang.NullPointerException
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2255)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2309)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread.access$700(ActivityThread.java:157)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.os.Looper.loop(Looper.java:176)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread.main(ActivityThread.java:5317)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at java.lang.reflect.Method.invokeNative(Native Method)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at java.lang.reflect.Method.invoke(Method.java:511)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at dalvik.system.NativeStart.main(Native Method)
08-01 00:55:10.045: E/AndroidRuntime(26849): Caused by: java.lang.NullPointerException
08-01 00:55:10.045: E/AndroidRuntime(26849):    at com.haider.first.Util.activateVibration(Util.java:30)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at com.haider.first.Util.onCreate(Util.java:20)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.Activity.performCreate(Activity.java:5326)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
08-01 00:55:10.045: E/AndroidRuntime(26849):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2218)
08-01 00:55:10.045: E/AndroidRuntime(26849):    ... 11 more

i am facing error "unable to find activitycomponentinfo, java.lang.runtimeexception" plzz helpppp !!

1 个答案:

答案 0 :(得分:0)

您的Util课程不需要展开{​​{1}}(当Activity展开时,当您使用Activity启动时,会出现一个新窗口。所以你需要这样做(Intent(如果你使用Right click on java folder--->New Java class,并且不扩展Android Studio):

Activity

并在您的活动中调用public class Util{ private AudioManager audi = null; //Method for activate vibration private void activateVibration() { // TODO Auto-generated method stub audi = (AudioManager) getSystemService(AUDIO_SERVICE); audi.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); } }

method

我认为您需要了解有关switch(item.getItemId()){ case R.id.item1: //Object initialization Util myUtil = new Util(); //Call activateVibration() method myUtil.activateVibration(); return true; case R.id.item2: startActivity(new Intent(Profile.this,Custom.class)); return true; default: return super.onContextItemSelected(item); } Java概念的更多信息才能开始开发OOP个应用。

希望它有所帮助!