Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. 04-15 15:50:16.676: E/AndroidRuntime(24520): FATAL EXCEPTION: main
  2. 04-15 15:50:16.676: E/AndroidRuntime(24520): Process: dado.auto3gdataswitch, PID: 24520
  3. 04-15 15:50:16.676: E/AndroidRuntime(24520): java.lang.RuntimeException: Unable to resume activity {dado.auto3gdataswitch/dado.auto3gdataswitch.MainActivity}: java.lang.NullPointerException
  4. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2788)
  5. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2817)
  6. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
  7. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.access$800(ActivityThread.java:135)
  8. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  9. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.os.Handler.dispatchMessage(Handler.java:102)
  10. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.os.Looper.loop(Looper.java:136)
  11. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.main(ActivityThread.java:5017)
  12. 04-15 15:50:16.676: E/AndroidRuntime(24520): at java.lang.reflect.Method.invokeNative(Native Method)
  13. 04-15 15:50:16.676: E/AndroidRuntime(24520): at java.lang.reflect.Method.invoke(Method.java:515)
  14. 04-15 15:50:16.676: E/AndroidRuntime(24520): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  15. 04-15 15:50:16.676: E/AndroidRuntime(24520): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  16. 04-15 15:50:16.676: E/AndroidRuntime(24520): at dalvik.system.NativeStart.main(Native Method)
  17. 04-15 15:50:16.676: E/AndroidRuntime(24520): Caused by: java.lang.NullPointerException
  18. 04-15 15:50:16.676: E/AndroidRuntime(24520): at dado.auto3gdataswitch.MainActivity.onResume(MainActivity.java:112)
  19. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
  20. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.Activity.performResume(Activity.java:5310)
  21. 04-15 15:50:16.676: E/AndroidRuntime(24520): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2778)
  22. 04-15 15:50:16.676: E/AndroidRuntime(24520): ... 12 more
  23.  
  24. import android.app.Activity;
  25. import android.content.ComponentName;
  26. import android.content.Context;
  27. import android.content.Intent;
  28. import android.content.SharedPreferences;
  29. import android.content.pm.PackageManager;
  30. import android.net.ConnectivityManager;
  31. import android.net.wifi.WifiManager;
  32. import android.os.Bundle;
  33. import android.preference.PreferenceManager;
  34. import android.view.View;
  35. import android.widget.Button;
  36. import android.widget.TextView;
  37. import android.widget.Toast;
  38.  
  39. public class MainActivity extends Activity {
  40.  
  41. @Override
  42. protected void onCreate(Bundle savedInstanceState) {
  43. super.onCreate(savedInstanceState);
  44. setContentView(R.layout.main);
  45.  
  46. final PackageManager pm = getPackageManager();
  47. final ComponentName compName = new ComponentName(getApplicationContext(),NetworkReceiver.class);
  48. final Button button = (Button) findViewById(R.id.button1);
  49. final ConnectivityManager conman = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
  50. final WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
  51. int isEnabled = pm.getComponentEnabledSetting(compName);
  52.  
  53.  
  54. if (isEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
  55. Toast.makeText(MainActivity.this, R.string.broadcastStop, Toast.LENGTH_SHORT).show();
  56. button.setText(R.string.btEnable);
  57. }
  58. else {
  59.  
  60. wifiManager.setWifiEnabled(true);
  61. Intent i = new Intent(getBaseContext(), MainService.class);
  62. startService(i);
  63. Toast.makeText(MainActivity.this, R.string.broadcastRun, Toast.LENGTH_SHORT).show();
  64. button.setText(R.string.btDisable);
  65. }
  66.  
  67. button.setOnClickListener(new View.OnClickListener() {
  68.  
  69. @Override
  70. public void onClick(View v) {
  71.  
  72. int isEnabled = pm.getComponentEnabledSetting(compName);
  73. if (isEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
  74.  
  75. wifiManager.setWifiEnabled(true);
  76. Intent i = new Intent(getBaseContext(), MainService.class);
  77. startService(i);
  78. pm.setComponentEnabledSetting(compName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
  79. Toast.makeText(MainActivity.this, R.string.broadcastRun, Toast.LENGTH_SHORT).show();
  80. button.setText(R.string.btDisable);
  81. }
  82. else {
  83.  
  84. pm.setComponentEnabledSetting(compName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);
  85. Toast.makeText(MainActivity.this, R.string.broadcastStop, Toast.LENGTH_SHORT).show();
  86. button.setText(R.string.btEnable);
  87. }
  88. }
  89. });
  90.  
  91. }
  92.  
  93. @Override
  94. protected void onResume() {
  95. // TODO Auto-generated method stub
  96. super.onResume();
  97.  
  98. final TextView vibration = (TextView) findViewById(R.id.getVibro);
  99. final TextView sound = (TextView) findViewById(R.id.getSound);
  100.  
  101. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  102.  
  103. if (prefs.getBoolean(PreferencesActivity.SOUND, false)) {
  104. sound.setText(getString(R.string.soundOn));
  105. }
  106. else {
  107. sound.setText("BLABLA");<<ERROR HERE
  108. }
  109. if (prefs.getBoolean(PreferencesActivity.VIBRO, false)) {
  110. vibration.setText(getString(R.string.vibroOn));
  111. }
  112. else {
  113. vibration.setText(getString(R.string.vibroOff));
  114. }
  115. }
  116.  
  117. sound.setText(R.string.soundOff);
  118.  
  119. sound.setText(getString(R.string.soundOff));
  120.  
  121. Caused by: java.lang.NullPointerException
  122. at dado.auto3gdataswitch.MainActivity.onResume(MainActivity.java:113)
  123.  
  124. public class MainActivity extends Activity {
  125.  
  126. @Override
  127. protected void onCreate(Bundle savedInstanceState) {
  128. super.onCreate(savedInstanceState);
  129. setContentView(R.layout.main);
  130. final TextView vibration = (TextView) findViewById(R.id.getVibro);
  131. final TextView sound = (TextView) findViewById(R.id.getSound);
  132. //Rest of the code
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement