我使用 Android Studio 创建了一个 Android 应用程序,并且没有编译错误或警告。但是当我在 Android Studio 的模拟器中运行该应用程序时,它显示了 mainActivity,我在其中放置了城市名称以显示天气,但是当我单击 fab 按钮时,该应用程序突然停止。请告诉我我错在哪里?以下是主要活动的代码:package com.bca.weatherapp;import android.os.AsyncTask;import android.os.Bundle;import android.support.design.widget.FloatingActionButton;import android.support.design.widget.Snackbar;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.View;import android.view.Menu;import android.view.MenuItem;import android.widget.EditText;import android.widget.TextView;import android.widget.Toast;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.UnsupportedEncodingException;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;/*Steps* 1. Designing Layout* 2. Declaring widgets* 3. Understandnig JSON* 4. Making AsyncTast to receive JSON* 5. Making JSON Objects and clarify the data* 6. Testing...* http://api.openweathermap.org/data/2.5/myWeather?q=Beirut&APPID=efed6aa0ebe9434cfd2b425089ea8392* */public class MainActivity extends AppCompatActivity { EditText cityField; TextView resultWeather; String cityToFind; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); cityField = (EditText) findViewById(R.id.editText); resultWeather = (TextView) findViewById(R.id.textView2);
添加回答
举报
0/150
提交
取消