-1

hi this is my first question because i'm new to android world programs

I want to take wifi rssi reading and disply it on list I write the code below and when run it on my phone ,the program stop and say "sorry program is stop " I dont know why??? could any one help me please ???

public class MainActivity extends ActionBarActivity {

    ListView list;
    WifiManager wifiManager;
    IntentFilter filter;
    String wifi [];
    WifiScanClass myClass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list=(ListView)findViewById(R.id.list1);
        wifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
         myClass = new WifiScanClass();
                    registerReceiver(myClass,new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
                    wifiManager.startScan();
    }
    protected void onResume()
    {
        filter=new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
        registerReceiver(myClass,filter);
        super.onResume();
    }
    protected void onPause()
    {
        unregisterReceiver(myClass);
        super.onPause();
    }

    class WifiScanClass extends BroadcastReceiver {
        @SuppressLint("UseValueOf")
        public void onReceive(Context context, Intent intent) {
            List<ScanResult> listResult=wifiManager.getScanResults();
            wifi=new String[listResult.size()];
            int i;
            for (i=0;i<listResult.size();i++);
            wifi[i]=((listResult.get(i)).toString());
            list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,wifi));

        }
    }
}
ENG_1990
  • 1
  • 3
  • along with "relevant" code you also need to post your logcat !! – AADProgramming Feb 02 '15 at 12:53
  • Possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – Zoe May 16 '19 at 11:01

2 Answers2

-1

Please add the Logcat output for the error. A possible source of the problem could be that getApplicationContext() needs to be called on the supplied context. So try to replace getApplicationContext() with context.getApplicationContext().

Templerschaf
  • 142
  • 1
  • 8
-1
public class MainActivity extends ActionBarActivity {

    ListView list;
    WifiManager wifiManager;
    IntentFilter filter;
    String wifi [];
    WifiScanClass myClass;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);




        list=(ListView)findViewById(R.id.list1);
        wifiManager=(WifiManager)getSystemService(Context.WIFI_SERVICE);
        myClass = new WifiScanClass();
        wifiManager.startScan();


    }


    protected void onResume()
    {
        filter=new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
        registerReceiver(myClass,filter);
        super.onResume();

    }

    protected void onPause()
    {

        unregisterReceiver(myClass);
        super.onPause();

    }

    class WifiScanClass extends BroadcastReceiver {


        @SuppressLint("UseValueOf")
        public void onReceive(Context context, Intent intent) {
            List<ScanResult> listResult=wifiManager.getScanResults();
            wifi=new String[listResult.size()];

            int i;
            for (i=0;i<listResult.size();i++)

                wifi[i]=((listResult.get(i)).toString());

            list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,wifi));


        }
    }
}

finally i found the error

";" in for loop .

ENG_1990
  • 1
  • 3
  • You made a simple mistake (we all do) but there is no point in keeping the question as nothing specific can be learned from it. So: please delete your question! – Hans Lub Feb 02 '15 at 19:53