Note that there are some explanatory texts on larger screens.

plurals
  1. POnull pointer exception only on tablet
    primarykey
    data
    text
    <p>hi my program works fine on portrait mode and phones but in tablets it wont work and forcecloses the error is this </p> <blockquote> <p></p> </blockquote> <pre><code>05-31 07:07:10.888: E/AndroidRuntime(1012): FATAL EXCEPTION: main 05-31 07:07:10.888: E/AndroidRuntime(1012): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.soheil.prolight/com.soheil.prolight.MainActivity}: java.lang.NullPointerException: println needs a message 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread.access$600(ActivityThread.java:123) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.os.Handler.dispatchMessage(Handler.java:99) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.os.Looper.loop(Looper.java:137) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread.main(ActivityThread.java:4424) 05-31 07:07:10.888: E/AndroidRuntime(1012): at java.lang.reflect.Method.invokeNative(Native Method) 05-31 07:07:10.888: E/AndroidRuntime(1012): at java.lang.reflect.Method.invoke(Method.java:511) 05-31 07:07:10.888: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 05-31 07:07:10.888: E/AndroidRuntime(1012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-31 07:07:10.888: E/AndroidRuntime(1012): at dalvik.system.NativeStart.main(Native Method) 05-31 07:07:10.888: E/AndroidRuntime(1012): Caused by: java.lang.NullPointerException: println needs a message 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.util.Log.println_native(Native Method) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.util.Log.e(Log.java:231) 05-31 07:07:10.888: E/AndroidRuntime(1012): at com.soheil.prolight.MainActivity.getCamera(MainActivity.java:184) 05-31 07:07:10.888: E/AndroidRuntime(1012): at com.soheil.prolight.MainActivity.onCreate(MainActivity.java:146) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.Activity.performCreate(Activity.java:4465) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-31 07:07:10.888: E/AndroidRuntime(1012): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) </code></pre> <p>and here is my code consider that im not taking anyyy errors on phones :</p> <pre><code>public class MainActivity extends Activity { ImageButton btnSwitch; ImageButton morebtn; ToggleButton tb_mute; AudioManager mAudioManager; boolean mute; private Camera camera; private boolean isFlashOn; private boolean hasFlash; Parameters params; MediaPlayer mp; float oldBrightNess = 0; float newBrightNess = 1.0f; //add private AdView adView; public ContextWrapper context; public Object paramString; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); //ads //papaya AppFlood.initialize(this, "XXXXXXXXX", "xxxxxxxxxxxxxxxx", AppFlood.AD_ALL); // Look up the AdView as a resource and load a request. AdView adView = (AdView)this.findViewById(R.id.adView); AdRequest adRequest = new AdRequest(); LinearLayout layout = (LinearLayout) findViewById(R.id.mainline); // Initiate a generic request to load it with an ad adView.loadAd(adRequest); morebtn = (ImageButton) findViewById(R.id.imageButton1); morebtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent newActivity = new Intent(MainActivity.this,more.class); startActivity(newActivity); } }); // flash switch button btnSwitch = (ImageButton) findViewById(R.id.btnSwitch); //Mute tb_mute = (ToggleButton) findViewById(R.id.toggleButton1); mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); if(mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC)==0){ mute = true; tb_mute.setChecked(mute); }else{ mute = false; tb_mute.setChecked(mute); } tb_mute.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(!mute){ mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true); tb_mute.setChecked(true); mute = true; }else{ mAudioManager.setStreamMute(AudioManager.STREAM_MUSIC, false); tb_mute.setChecked(false); mute = false; } } }); // First check if device is supporting flashlight or not hasFlash = getApplicationContext().getPackageManager() .hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH); getCamera(); btnSwitch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!hasFlash) { // turn off flash Intent newActivity = new Intent(MainActivity.this,screenlight.class); startActivity(newActivity); turnOffFlash(); } else if (hasFlash &amp;&amp; isFlashOn) { playSound(); toggleButtonImage(); // turn off flash turnOffFlash(); } else { playSound(); toggleButtonImage(); // turn on flash turnOnFlash(); } } }); return; } // Get the camera private void getCamera() { if (camera == null) { try { camera = Camera.open(); params = camera.getParameters(); } catch (RuntimeException e) { Log.e("Camera Error. Failed to Open. Error: ", e.getMessage()); } } } // Turning On flash private void turnOnFlash() { if (!isFlashOn) { if (camera == null || params == null) { return; } // play sound playSound(); params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_TORCH); camera.setParameters(params); camera.startPreview(); isFlashOn = true; // changing button/switch image toggleButtonImage(); } } // Turning Off flash private void turnOffFlash() { if (isFlashOn) { if (camera == null || params == null) { return; } // play sound playSound(); params = camera.getParameters(); params.setFlashMode(Parameters.FLASH_MODE_OFF); camera.setParameters(params); camera.stopPreview(); isFlashOn = false; // changing button/switch image toggleButtonImage(); } } // Playing sound // will play button toggle sound on flash on / off private void playSound(){ if(isFlashOn){ mp = MediaPlayer.create(MainActivity.this, R.raw.beep); }else{ mp = MediaPlayer.create(MainActivity.this, R.raw.beep); } mp.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mp.release(); } }); mp.start(); } /* * Toggle switch button images * changing image states to on / off * */ private void toggleButtonImage(){ if(isFlashOn){ btnSwitch.setImageResource(R.drawable.btn_switch_on); }else{ btnSwitch.setImageResource(R.drawable.btn_switch_off); } } @Override protected void onPause() { if (adView != null) { adView.destroy(); } super.onPause(); } @Override protected void onDestroy() { if (adView != null) { adView.destroy(); } AppFlood.destroy(); super.onDestroy(); } @Override protected void onRestart() { super.onRestart(); } @Override protected void onResume() { super.onResume(); } @Override protected void onStart() { super.onStart(); turnOnFlash(); // on starting the app get the camera params getCamera(); } @Override protected void onStop() { super.onStop(); // on stop release the camera if (camera != null) { camera.release(); camera = null; } } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater=getMenuInflater(); inflater.inflate(R.menu.mymenu, menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { if(item.getItemId()==R.id.item1){ Dialog d=new Dialog(MainActivity.this); d.setContentView(R.layout.aboutdialog); d.setTitle("About"); d.show(); } return super.onOptionsItemSelected(item); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { finish(); } return super.onKeyDown(keyCode, event); } } </code></pre> <p>and if u want my layout xml code here it is :</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/background" android:gravity="top" tools:context=".MainActivity" &gt; &lt;ImageButton android:id="@+id/btnSwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_marginTop="25dp" android:background="@null" android:contentDescription="@null" android:src="@drawable/btn_switch_on" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView2" android:layout_centerHorizontal="true" android:text="@string/Develop" android:textColor="#C0C0C0" android:textSize="15sp" /&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:padding="5dp" android:text="@string/soheilen" android:textColor="#C0C0C0" android:textSize="18sp" /&gt; &lt;ImageButton android:id="@+id/imageButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:background="@null" android:contentDescription="@null" android:minHeight="64dp" android:minWidth="64dp" android:src="@drawable/more" /&gt; &lt;ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="@string/mute" android:textOff="@string/mute" android:textOn="@string/mute" /&gt; &lt;LinearLayout android:layout_height="wrap_content" android:orientation="vertical" android:layout_width="fill_parent" android:id="@+id/mainline" android:gravity="top" &gt; &lt;com.google.ads.AdView android:id="@+id/adView" android:layout_width="match_parent" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="xxxxxxxx" ads:loadAdOnCreate="true" android:gravity="top" &gt; &lt;/com.google.ads.AdView&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>i wonder where is the error come from ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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