Note that there are some explanatory texts on larger screens.

plurals
  1. PObutton.performclick() is not working
    text
    copied!<p>I have a simple code which records video on clicking a button. Manual click works fine but <code>myButton.performClick()</code> does not work (the app stops). I have tried setPressed() too but the click by it does not cause any effect. If I directly start mediarecorder without any button click, then also the app crashes. I am clueless.</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); recording = false; setContentView(R.layout.main); //Get Camera for preview myCamera = getCameraInstance(); if(myCamera == null){ Toast.makeText(AndroidVideoCapture.this, "Fail to get Camera", Toast.LENGTH_LONG).show(); } myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera); FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview); myCameraPreview.addView(myCameraSurfaceView); myButton = (Button)findViewById(R.id.mybutton); myButton.setOnClickListener(myButtonOnClickListener); myButton.performClick(); } Button.OnClickListener myButtonOnClickListener = new Button.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub if(recording){ // stop recording and release camera mediaRecorder.stop(); // stop the recording releaseMediaRecorder(); // release the MediaRecorder object //Exit after saved finish(); }else{ //Release Camera before MediaRecorder start releaseCamera(); if(!prepareMediaRecorder()){ Toast.makeText(AndroidVideoCapture.this, "Fail in prepareMediaRecorder()!\n - Ended -", Toast.LENGTH_LONG).show(); finish(); } mediaRecorder.start(); recording = true; myButton.setText("STOP"); } }}; </code></pre> <p>My log file-</p> <pre><code> 05-16 12:40:35.680: E/MediaRecorderJNI(1710): Application lost the surface 05-16 12:40:35.680: E/AndroidRuntime(1710): in writeCrashedAppName, pkgName :com.exercise.AndroidVideoCapture 05-16 12:40:35.680: E/AndroidRuntime(1710): FATAL EXCEPTION: main 05-16 12:40:35.680: E/AndroidRuntime(1710): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exercise.AndroidVideoCapture/com.exercise.AndroidVideoCapture.AndroidVideoCapture}: java.lang.NullPointerException 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.os.Handler.dispatchMessage(Handler.java:99) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.os.Looper.loop(Looper.java:130) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread.main(ActivityThread.java:3683) 05-16 12:40:35.680: E/AndroidRuntime(1710): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 12:40:35.680: E/AndroidRuntime(1710): at java.lang.reflect.Method.invoke(Method.java:507) 05-16 12:40:35.680: E/AndroidRuntime(1710): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880) 05-16 12:40:35.680: E/AndroidRuntime(1710): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638) 05-16 12:40:35.680: E/AndroidRuntime(1710): at dalvik.system.NativeStart.main(Native Method) 05-16 12:40:35.680: E/AndroidRuntime(1710): Caused by: java.lang.NullPointerException 05-16 12:40:35.680: E/AndroidRuntime(1710): at com.exercise.AndroidVideoCapture.AndroidVideoCapture$1.onClick(AndroidVideoCapture.java:145) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.view.View.performClick(View.java:2485) 05-16 12:40:35.680: E/AndroidRuntime(1710): at com.exercise.AndroidVideoCapture.AndroidVideoCapture.onCreate(AndroidVideoCapture.java:74) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-16 12:40:35.680: E/AndroidRuntime(1710): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 05-1 </code></pre> <p>6 12:40:35.680: E/AndroidRuntime(1710): ... 11 more</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload