title: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS }
body: <p>okay, the full error is</p>
  
  <pre><code>06-19 01:07:57.421: E/AndroidRuntime(4478): java.lang.RuntimeException: Error 
  receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS } in 
  com.blucalc.netfind.WiFiScanReceiver@40521ba0
  </code></pre>
  
  <p>com.blucalc.netfind is my package
  WiFiScanReceiver is the class its crashing in.</p>
  
  <p>the class is here:</p>
  
  <pre><code>package com.blucalc.netfind;
  
  import java.util.List;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.net.wifi.ScanResult;
  
  public class WiFiScanReceiver extends BroadcastReceiver {
      NetworkfinderActivity netfinder;
  
      public WiFiScanReceiver(NetworkfinderActivity netfinder) {
          super();
          this.netfinder = netfinder;
      }
  
      @Override
      public void onReceive(Context c, Intent intent) {
          System.out.println("onReceive(Context=" + c.toString() + "Intent="
                  + intent.toString());
          List&lt;ScanResult&gt; results = netfinder.wifi.getScanResults();
          netfinder.processResults(results);
      }
  
  }
  </code></pre>
  
  <p>NetworkfinderActivity is the main class thing.</p>
  
  <p>the really strange thing about the error is, it only happens on the second time this function is called. whether thats because of the different data i dont know, i can't test.</p>
  
  <p>can someone please help me?</p>
  
  <p>edit1:
  as requested, androidmanifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.blucalc.netfind"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="7" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
          &lt;activity
              android:name=".NetworkfinderActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>here's the main class. where all the fun happens.</p>
  
  <pre><code>//some code borrowed from http://marakana.com/forums/android/examples/40.html
  package com.blucalc.netfind;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.BroadcastReceiver;
  import android.content.IntentFilter;
  import android.os.Bundle;
  import android.net.wifi.*;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.*;
  
  
  public class NetworkfinderActivity extends Activity {
      /** Called when the activity is first created. */
      WifiManager wifi;
      BroadcastReceiver receiver;
      List&lt;FrameLayout&gt; netlist;
      LinearLayout ll;
      Button b;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          System.out.println("start of main constructor");
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          //a couple interface elements I want to access
          ll = (LinearLayout)findViewById(R.id.networkList);
          b = (Button)findViewById(R.id.refreshButton);
          //initialisation of some memory
          netlist=new ArrayList&lt;FrameLayout&gt;();
          //where all network info comes from
          wifi=(WifiManager)getSystemService(WIFI_SERVICE);
          // Register Broadcast Receiver
          receiver = new WiFiScanReceiver(this);
          registerReceiver(receiver, new IntentFilter(
                  WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
  
          b.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {;
              System.out.println("clicked");
                  ll.removeAllViews();
                  netlist.clear();
  
                  wifi.startScan();
              }
          });
          System.out.println("end of main constructor");
      }
  
      @Override
      public void onStop() {
          unregisterReceiver(receiver);
      }
      public void processResults(List&lt;ScanResult&gt; results)
      {
          System.out.println("processResults(results "+results.toString());
          ll.removeAllViews();
          netlist.clear();
          for (ScanResult result:results)
          {
              readResult(result);
          }
          System.out.println("end of processResults");
  
      }
      public void readResult(ScanResult result)
      {
          System.out.println("readResult(result "+result.toString());
          FrameLayout frame=new FrameLayout(this);
          TextView ssid=new TextView(this);
          TextView strength=new TextView(this);
          System.out.println("1");
          int level=result.level;
          System.out.println("level="+level);
          int signal=WifiManager.calculateSignalLevel(level, 100)+1;
          //signal will be strength of the signal as a percent (from 1 to 100)
          System.out.println("signal="+signal);
  
          strength.setText(new Integer(signal).toString());
          ssid.setText(result.SSID);
          TextView cheat=new TextView(this);
          cheat.setText(result.toString());
  
  //      frame.addView(ssid);
  //      frame.addView(strength);
          frame.addView(cheat);
  
          netlist.add(frame);
          ll.addView(netlist.get(netlist.size()-1));
          System.out.println("end of readResults");
      }
  
  }
  </code></pre>
  
  <p>and last but not least, here's the entire output, plus all error messages.</p>
  
  <pre><code>06-20 20:40:06.835: I/ApplicationPackageManager(2399): cscCountry is not German : XSA
  06-20 20:40:06.835: I/System.out(2399): start of main constructor
  06-20 20:40:06.867: V/WifiProgressStore(2399): WifiProgressStore Created
  06-20 20:40:06.867: I/System.out(2399): end of main constructor
  06-20 20:40:16.765: I/System.out(2399): clicked
  06-20 20:40:17.351: I/System.out(2399): onReceive(Context=com.blucalc.netfind.NetworkfinderActivity@40518050Intent=Intent { act=android.net.wifi.SCAN_RESULTS }
  06-20 20:40:17.363: I/System.out(2399): processResults(results [SSID: BluCalculator, BSSID: f4:ec:38:a9:1d:56, capabilities: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][WPS], level: -51, frequency: 2412, SSID: BigAir, BSSID: 06:27:22:b3:41:7e, capabilities: , level: -72, frequency: 2437, SSID: BigAir, BSSID: 06:27:22:5f:56:d8, capabilities: , level: -87, frequency: 2437]
  06-20 20:40:17.367: I/System.out(2399): readResult(result SSID: BluCalculator, BSSID: f4:ec:38:a9:1d:56, capabilities: [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][WPS], level: -51, frequency: 2412
  06-20 20:40:17.375: I/System.out(2399): 1
  06-20 20:40:17.375: I/System.out(2399): level=-51
  06-20 20:40:17.375: I/System.out(2399): signal=100
  06-20 20:40:17.378: I/System.out(2399): end of readResults
  06-20 20:40:17.382: I/System.out(2399): readResult(result SSID: BigAir, BSSID: 06:27:22:b3:41:7e, capabilities: , level: -72, frequency: 2437
  06-20 20:40:17.390: I/System.out(2399): 1
  06-20 20:40:17.390: I/System.out(2399): level=-72
  06-20 20:40:17.394: D/AndroidRuntime(2399): Shutting down VM
  06-20 20:40:17.394: W/dalvikvm(2399): threadid=1: thread exiting with uncaught exception (group=0x40015578)
  06-20 20:40:17.402: E/AndroidRuntime(2399): FATAL EXCEPTION: main
  06-20 20:40:17.402: E/AndroidRuntime(2399): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.wifi.SCAN_RESULTS } in com.blucalc.netfind.WiFiScanReceiver@40520ec0
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:722)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.os.Handler.handleCallback(Handler.java:587)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.os.Handler.dispatchMessage(Handler.java:92)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.os.Looper.loop(Looper.java:123)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.app.ActivityThread.main(ActivityThread.java:3687)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at java.lang.reflect.Method.invoke(Method.java:507)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at dalvik.system.NativeStart.main(Native Method)
  06-20 20:40:17.402: E/AndroidRuntime(2399): Caused by: java.lang.ArithmeticException: divide by zero
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.net.wifi.WifiManager.calculateSignalLevel(WifiManager.java:957)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at com.blucalc.netfind.NetworkfinderActivity.readResult(NetworkfinderActivity.java:79)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at com.blucalc.netfind.NetworkfinderActivity.processResults(NetworkfinderActivity.java:65)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at com.blucalc.netfind.WiFiScanReceiver.onReceive(WiFiScanReceiver.java:23)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:709)
  06-20 20:40:17.402: E/AndroidRuntime(2399):     ... 9 more
  </code></pre>