解决方案 »

  1.   

    你是不是用了第三方的jar包了?
      

  2.   

    下面贴一点代码吧:
    WebServiceUtil.java:public static SoapObject getWeatherByCity(String cityName)
    {
    /**
     * 获得天气预报数据        输入参数:城市/地区ID或名称,返回数据:一维字符串数组。
           如:输入theCityCode:792(<string>北京,792</string>)得到的返回结果为:
           This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://WebXml.com.cn/">
    <string>直辖市 北京</string>
    <string>北京</string>
    <string>792</string>
    <string>2013/04/30 03:47:53</string>
    <string>今日天气实况:气温:14℃;风向/风力:东风 2级;湿度:21%</string>
    <string>空气质量:良;紫外线强度:强</string>
    <string>
    穿衣指数:建议着薄型套装等春秋过渡装。年老体弱者宜着套装。但昼夜温差较大,注意适当增减衣服。 过敏指数:天气条件极易诱发过敏,易过敏人群尽量减少外出,外出宜穿长衣长裤并佩戴好眼镜和口罩,外出归来时及时清洁手和口鼻。 运动指数:天气较好,但由于风力较大,推荐您在室内进行低强度运动,若在户外运动请注意避风。 洗车指数:适宜洗车,未来持续两天无雨天气较好,适合擦洗汽车,蓝天白云、风和日丽将伴您的车子连日洁净。 晾晒指数:天气不错,适宜晾晒。赶紧把久未见阳光的衣物搬出来吸收一下太阳的味道吧! 旅游指数:天气较好,风稍大,但温度适宜,是个好天气哦。很适宜旅游,您可以尽情地享受大自然的无限风光。 路况指数:天气较好,路面比较干燥,路况较好。 舒适度指数:白天天气晴好,您在这种天气条件下,会感觉早晚凉爽、舒适,午后偏热。 空气污染指数:气象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。 紫外线指数:紫外线辐射强,建议涂擦SPF20左右、PA++的防晒护肤品。避免在10点至14点暴露于日光下。
    </string>
    <string>4月30日 晴</string>
    <string>11℃/27℃</string>
    <string>北风3-4级转无持续风向微风</string>
    <string>0.gif</string>
    <string>0.gif</string>
    <string>5月1日 晴转多云</string>
    <string>12℃/25℃</string>
    <string>无持续风向微风</string>
    <string>0.gif</string>
    <string>1.gif</string>
    <string>5月2日 多云转晴</string>
    <string>13℃/26℃</string>
    <string>无持续风向微风</string>
    <string>1.gif</string>
    <string>0.gif</string>
    <string>5月3日 多云转阴</string>
    <string>11℃/23℃</string>
    <string>无持续风向微风</string>
    <string>1.gif</string>
    <string>2.gif</string>
    <string>5月4日 阴转多云</string>
    <string>14℃/27℃</string>
    <string>无持续风向微风</string>
    <string>2.gif</string>
    <string>1.gif</string>
    </ArrayOfString>  */
    String methodName = "getWeather";
    HttpTransportSE ht = new HttpTransportSE(SERVICE_URL);
    ht.debug = true;
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    SoapObject soapObject = new SoapObject(SERVICE_NS, methodName);
    soapObject.addProperty("theCityCode", cityName);
    envelope.bodyOut = soapObject;
    // 设置与.Net提供的Web Service保持较好的兼容性
    envelope.dotNet = true;
    try
    {
    ht.call(SERVICE_NS + methodName, envelope);
    SoapObject result = (SoapObject) envelope.bodyIn;
    SoapObject detail = (SoapObject) result.getProperty(methodName+ "Result");
    return detail;
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    return null;
    }
    这是其中有一点警告的一段,说是:The word 'gif' is not correctly spelled
      

  3.   

    你把第三方的jar包放在libs目录下,如果没有就新建一个.
      

  4.   

    我再贴下引用了第三方jar包ksoap2-android-assembly-2.5.4-jar-with-dependencies的MainActivity的代码:
    import java.util.List;
    import org.ksoap2.serialization.SoapObject;
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ImageView;
    import android.widget.Spinner;
    import android.widget.TextView;
    import android.widget.AdapterView.OnItemSelectedListener;public class MainActivity extends Activity { private Spinner provinceSpinner;
    private Spinner citySpinner;
    private ImageView todayWhIcon1;
    private ImageView todayWhIcon2;
    private TextView textWeatherToday;
    private ImageView tomorrowWhIcon1;
    private ImageView tomorrowWhIcon2;
    private TextView textWeatherTomorrow;
    private ImageView afterdayWhIcon1;
    private ImageView afterdayWhIcon2;
    private TextView textWeatherAfterday;
    private TextView textWeatherCurrent;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    todayWhIcon1 = (ImageView) findViewById(R.id.todayWhIcon1);
    todayWhIcon2 = (ImageView) findViewById(R.id.todayWhIcon2);
    textWeatherToday = (TextView) findViewById(R.id.weatherToday);
    tomorrowWhIcon1 = (ImageView) findViewById(R.id.tomorrowWhIcon1);
    tomorrowWhIcon2 = (ImageView) findViewById(R.id.tomorrowWhIcon2);
    textWeatherTomorrow = (TextView) findViewById(R.id.weatherTomorrow);
    afterdayWhIcon1 = (ImageView) findViewById(R.id.afterdayWhIcon1);
    afterdayWhIcon2 = (ImageView) findViewById(R.id.afterdayWhIcon2);
    textWeatherAfterday = (TextView) findViewById(R.id.weatherAfterday);
    textWeatherCurrent = (TextView) findViewById(R.id.weatherCurrent); // 获取程序界面中选择省份、城市的Spinner组件
    provinceSpinner = (Spinner) findViewById(R.id.province);
    citySpinner = (Spinner) findViewById(R.id.city);
    // 调用远程Web Service获取省份列表
    List<String> provinces = WebServiceUtil.getProvinceList();
    ListAdapter adapter = new ListAdapter(this, provinces);
    // 使用Spinner显示省份列表
    provinceSpinner.setAdapter(adapter);
    // 当省份Spinner的选择项被改变时
    provinceSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
    {
    @Override
    public void onItemSelected(AdapterView<?> source, View parent,
    int position, long id)
    {
    // 根据省份获取城市列表
    List<String> cities = WebServiceUtil
    .getCityListByProvince(provinceSpinner.getSelectedItem()
    .toString());
    ListAdapter cityAdapter = new ListAdapter(MainActivity.this,
    cities);
    // 使用Spinner显示城市列表
    citySpinner.setAdapter(cityAdapter);
    } @Override
    public void onNothingSelected(AdapterView<?> arg0)
    {
    }
    });
    // 当城市Spinner的选择项被改变时
    citySpinner.setOnItemSelectedListener(new OnItemSelectedListener()
    {
    @Override
    public void onItemSelected(AdapterView<?> source, View parent,
    int position, long id)
    {
    //展现天气预报的具体数据
    showWeather(citySpinner.getSelectedItem().toString());
    } @Override
    public void onNothingSelected(AdapterView<?> arg0)
    {
    }
    });
    }
    //展现天气预报的具体数据
    private void showWeather(String city)
    {
    String weatherToday = null;
    String weatherTomorrow = null;
    String weatherAfterday = null;
    String weatherCurrent = null;
    int iconToday[] = new int[2];
    int iconTomorrow[] = new int[2];
    int iconAfterday[] = new int[2];
    // 获取远程Web Service返回的对象
    SoapObject detail = WebServiceUtil.getWeatherByCity(city);// 根据城市获取城市具体天气情况
    // 获取天气实况
    weatherCurrent = detail.getProperty(4).toString();
    // 解析今天的天气情况
    String date = detail.getProperty(7).toString();
    weatherToday = "今天:" + date.split(" ")[0];
    weatherToday = weatherToday + "\n天气:" + date.split(" ")[1];
    weatherToday = weatherToday + "\n气温:"
    + detail.getProperty(8).toString();
    weatherToday = weatherToday + "\n风力:"
    + detail.getProperty(9).toString() + "\n";
    iconToday[0] = parseIcon(detail.getProperty(10).toString());
    iconToday[1] = parseIcon(detail.getProperty(11).toString());
    // 解析明天的天气情况
    date = detail.getProperty(12).toString();
    weatherTomorrow = "明天:" + date.split(" ")[0];
    weatherTomorrow = weatherTomorrow + "\n天气:" + date.split(" ")[1];
    weatherTomorrow = weatherTomorrow + "\n气温:"
    + detail.getProperty(13).toString();
    weatherTomorrow = weatherTomorrow + "\n风力:"
    + detail.getProperty(14).toString() + "\n";
    iconTomorrow[0] = parseIcon(detail.getProperty(15).toString());
    iconTomorrow[1] = parseIcon(detail.getProperty(16).toString());
    // 解析后天的天气情况
    date = detail.getProperty(17).toString();
    weatherAfterday = "后天:" + date.split(" ")[0];
    weatherAfterday = weatherAfterday + "\n天气:" + date.split(" ")[1];
    weatherAfterday = weatherAfterday + "\n气温:"
    + detail.getProperty(18).toString();
    weatherAfterday = weatherAfterday + "\n风力:"
    + detail.getProperty(19).toString() + "\n";
    iconAfterday[0] = parseIcon(detail.getProperty(20).toString());
    iconAfterday[1] = parseIcon(detail.getProperty(21).toString());
    // 更新当天的天气实况
    textWeatherCurrent.setText(weatherCurrent);
    // 更新显示今天天气的图标和文本框
    textWeatherToday.setText(weatherToday);
    todayWhIcon1.setImageResource(iconToday[0]);
    todayWhIcon2.setImageResource(iconToday[1]);
    // 更新显示明天天气的图标和文本框
    textWeatherTomorrow.setText(weatherTomorrow);
    tomorrowWhIcon1.setImageResource(iconTomorrow[0]);
    tomorrowWhIcon2.setImageResource(iconTomorrow[1]);
    // 更新显示后天天气的图标和文本框
    textWeatherAfterday.setText(weatherAfterday);
    afterdayWhIcon1.setImageResource(iconAfterday[0]);
    afterdayWhIcon2.setImageResource(iconAfterday[1]);
    }
    private int parseIcon(String strIcon)
    {
    if (strIcon == null)
    return -1;
    if ("0.gif".equals(strIcon))
    return R.drawable.a_0;
    if ("1.gif".equals(strIcon))
    return R.drawable.a_1;
    if ("2.gif".equals(strIcon))
    return R.drawable.a_2;
    if ("3.gif".equals(strIcon))
    return R.drawable.a_3;
    if ("4.gif".equals(strIcon))
    return R.drawable.a_4;
    if ("5.gif".equals(strIcon))
    return R.drawable.a_5;
    if ("6.gif".equals(strIcon))
    return R.drawable.a_6;
    if ("7.gif".equals(strIcon))
    return R.drawable.a_7;
    if ("8.gif".equals(strIcon))
    return R.drawable.a_8;
    if ("9.gif".equals(strIcon))
    return R.drawable.a_9;
    if ("10.gif".equals(strIcon))
    return R.drawable.a_10;
    if ("11.gif".equals(strIcon))
    return R.drawable.a_11;
    if ("12.gif".equals(strIcon))
    return R.drawable.a_12;
    if ("13.gif".equals(strIcon))
    return R.drawable.a_13;
    if ("14.gif".equals(strIcon))
    return R.drawable.a_14;
    if ("15.gif".equals(strIcon))
    return R.drawable.a_15;
    if ("16.gif".equals(strIcon))
    return R.drawable.a_16;
    if ("17.gif".equals(strIcon))
    return R.drawable.a_17;
    if ("18.gif".equals(strIcon))
    return R.drawable.a_18;
    if ("19.gif".equals(strIcon))
    return R.drawable.a_19;
    if ("20.gif".equals(strIcon))
    return R.drawable.a_20;
    if ("21.gif".equals(strIcon))
    return R.drawable.a_21;
    if ("22.gif".equals(strIcon))
    return R.drawable.a_22;
    if ("23.gif".equals(strIcon))
    return R.drawable.a_23;
    if ("24.gif".equals(strIcon))
    return R.drawable.a_24;
    if ("25.gif".equals(strIcon))
    return R.drawable.a_25;
    if ("26.gif".equals(strIcon))
    return R.drawable.a_26;
    if ("27.gif".equals(strIcon))
    return R.drawable.a_27;
    if ("28.gif".equals(strIcon))
    return R.drawable.a_28;
    if ("29.gif".equals(strIcon))
    return R.drawable.a_29;
    if ("30.gif".equals(strIcon))
    return R.drawable.a_30;
    if ("31.gif".equals(strIcon))
    return R.drawable.a_31;
    return 0;
    }}
      

  5.   

    对的。
    别贴代码了,出错原因是因为没有找到相应的class文件.
      

  6.   

    试过了,出现logcat登录不上:[2013-06-06 10:30:17 - Unexpected error while launching logcat. Try reselecting the device.] device not found
      

  7.   

    eclipse 选中libs 目录右键 build as source folder 就会解决这个问题
      

  8.   

    对的。
    别贴代码了,出错原因是因为没有找到相应的class文件.
    哦,麻烦您能说得具体点么 
      

  9.   

    试过了,出现错误:
     Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
    这个dex是什么意思啊 ?麻烦您能详细解释一下么
      

  10.   


    会不会是这个output folder的问题,我打开MyWeather/bin/classes这个文件里面全是乱码。
      

  11.   

    dex是一种格式,专门为Dalvik设计的一种压缩格式,适用于内存和处理器速度有限的系统;要生成DEX格式文件,首先要通过java程序编译成.class文件,然后通过Android提供的dx工具将class文件转换成DEX.你的v4.jar应该有问题,实在不行新建一个工程,把用到的代码拷贝进去
      

  12.   


    试过了  还是一样的错误:
    [2013-06-06 23:34:28 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/kobjects/base64/Base64;
    [2013-06-06 23:34:28 - MyWeather1] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/kobjects/base64/Base64;
    意思好像是多重定义?
      

  13.   

    应该是jar 包重复使用了,删除所有引用的jar然后再一个个引用试试吧