令牌字符串上的语法错误

时间:2014-07-10 09:06:58

标签: java android

我试着把这段代码放进去,但是它有错误,该怎么办? 是的,因为我把公共字符串放在onStart()?

MediaPlayer playMusic;

@Override

protected void onStart() {

    public String getIpAddr() {
    // TODO Auto-generated method stub
        super.onStart();


           WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
           WifiInfo wifiInfo = wifiManager.getConnectionInfo();
           int ip = wifiInfo.getIpAddress();

           String ipString = String.format(
           "%d.%d.%d.%d",
           (ip & 0xff),
           (ip >> 8 & 0xff),
           (ip >> 16 & 0xff),
           (ip >> 24 & 0xff));

           return ipString;



    //for(int array;array < 256;array++)
    //try {

        //if("192.168.150.16".equals(WIFI_SERVICE))
    }

}

我应该创建一个新类吗?

1 个答案:

答案 0 :(得分:0)

试试这个......

@Override
protected void onStart() {
    getIpAddr();
    super.onStart();
}

public String getIpAddr() 
{

    WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();

    String ipString = String.format(
            "%d.%d.%d.%d",
            (ip & 0xff),
            (ip >> 8 & 0xff),
            (ip >> 16 & 0xff),
            (ip >> 24 & 0xff));

    return ipString;



    //for(int array;array < 256;array++)
    //try {

    //if("192.168.150.16".equals(WIFI_SERVICE))
}