Hugo Gao 2016-07-26 13:08 采纳率: 45.7%
浏览 983

Eclipse报了一个没见过的错

报错如下

 07-26 17:23:45.679: E/AndroidRuntime(26216): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myweathertest/com.example.myweathertest.activities.WeatherActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x0

Activity如下

 public class WeatherActivity extends Activity implements OnClickListener {
    private LinearLayout weatherInfoLayout;


    private TextView cityNameText;

    private TextView publishText;
    ;
    private TextView  weatherDespText;
    private TextView  temp1Text;
    private TextView  temp2Text;
    private TextView  currentDateText;
    private Button switchCity;
    private Button refreshWeather;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.weather_layout);
        weatherInfoLayout=(LinearLayout)findViewById(R.id.weather_info_layout);
        cityNameText=(TextView)findViewById(R.id.city_name);
        publishText=(TextView)findViewById(R.id.publish_text);
        weatherDespText=(TextView)findViewById(R.id.weather_desp);
        temp1Text=(TextView)findViewById(R.id.temp1);
        temp2Text=(TextView)findViewById(R.id.temp2);
        currentDateText=(TextView)findViewById(R.id.current_date);
        switchCity=(Button)findViewById(R.id.switch_city);
        refreshWeather=(Button)findViewById(R.id.refresh_weather);
        switchCity.setOnClickListener(this);
        refreshWeather.setOnClickListener(this);
        String countyName=getIntent().getStringExtra("county_name");
        if(!TextUtils.isEmpty(countyName))//若从菜单中点击进去
        {
            publishText.setText("同步中");
            weatherInfoLayout.setVisibility(View.INVISIBLE);
            cityNameText.setVisibility(View.INVISIBLE);
            queryWeatherInfo(countyName);
            showWeather();
        }else//若直接打开app
        {
            Log.d("haha", "countyName is null");
            showWeather();
        }
    }

    private void showWeather() {
        // TODO Auto-generated method stub
        Log.d("haha", "进入showweather");
        SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
        cityNameText.setText(prefs.getString("city_name", "未知错误"));
        temp1Text.setText(prefs.getString("temp1", ""));
        temp2Text.setText(prefs.getString("temp2", ""));
        weatherDespText.setText(prefs.getString("weather_desp", ""));
        publishText.setText(prefs.getString("publish_time", "")+"发布");
        currentDateText.setText(prefs.getString("current_time", ""));
        weatherInfoLayout.setVisibility(View.VISIBLE);
        cityNameText.setText(View.VISIBLE);

    }

    private void queryWeatherInfo(String countyName) {
        // TODO Auto-generated method stub
        Log.d("haha", "开始查询天气");
        String address="http://apis.baidu.com/heweather/weather/free";//http://apis.baidu.com/heweather/weather/free
        Parameters param=new Parameters();
        countyName=ChangeHanziToPinyin.getPinYin(countyName);
        Log.d("haha", "cityName is "+countyName);
        param.put("city", countyName);
        ApiStoreSDK.execute(address,    ApiStoreSDK.GET, param,new ApiCallBack() {
            @Override
            public void onSuccess(int status, String responseString) {
                Log.d("haha", "请求成功");
                    Utility.handleWeatherResponse(WeatherActivity.this, responseString);//存入了sharepreferce
            }

            @Override
            public void onComplete() {

            }

            @Override
            public void onError(int status, String responseString, Exception e) {
                    Log.d("haha", "错误进入onerror,参数为"+status);
            }  

    });
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub

    }
}

布局文件

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout 
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:background="#484E61"
        >
        <Button 
            android:id="@+id/switch_city"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@drawable/home"/>
        <TextView 
            android:id="@+id/city_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:textColor="#fff"
            android:textSize="24sp"
            />
        <Button 
            android:id="@+id/refresh_weather"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:background="@drawable/refresh"
         />
    </RelativeLayout>

        <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#27A5F9"
            >
            <TextView 
                android:id="@+id/publish_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:textColor="#FFF"
                android:textSize="18sp"/>
            <LinearLayout 
                android:id="@+id/weather_info_layout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:orientation="vertical">
                <TextView 
                    android:id="@+id/current_date"
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:gravity="center"
                    android:textColor="#FFF"
                    android:textSize="18sp"/>


                <TextView 
                    android:id="@+id/weather_desp"
                    android:layout_width="wrap_content"
                    android:layout_height="60dp"
                    android:layout_gravity="center_horizontal"
                    android:gravity="center"
                    android:textColor="#FFF"
                    android:textSize="40sp"/>
                                <LinearLayout 
                                        android:layout_width="wrap_content"
                                        android:layout_height="60dp"
                                        android:layout_gravity="center_horizontal"
                                        android:orientation="horizontal">

                                    <TextView 
                                        android:id="@+id/temp1"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_gravity="center_vertical"
                                        android:textColor="#FFF"
                                        android:textSize="40sp"
                                        />
                                    <TextView 
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_gravity="center_vertical"
                                        android:layout_marginLeft="10dp"
                                        android:layout_marginRight="10dp"
                                        android:text="~"
                                        android:textColor="#FFF"
                                        android:textSize="40sp"/>

                                    <TextView 
                                        android:id="@+id/temp2"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_gravity="center_vertical"
                                        android:textColor="#FFF"
                                        android:textSize="40sp"
                                        />
                                </LinearLayout>

            </LinearLayout>

        </RelativeLayout>

</LinearLayout>

为什么就不能启动这个Activity 呢,而且

 ApiStoreSDK.execute(address,   ApiStoreSDK.GET, param,new ApiCallBack() {

这行代码直接跳过去没执行,为什么?

  • 写回答

5条回答 默认 最新

  • threenewbee 2016-07-26 15:23
    关注

    提示信息是资源没有找到,检查下你的资源名、资源的路径,代码

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题