【发布时间】:2016-12-07 13:31:06
【问题描述】:
我有一个AsyncTask,我想在我的 layout.xml 文件中设置TextView 的文本,但是我的应用程序因错误而崩溃
android.content.res.Resources$NotFoundException: 字符串资源 ID #0x2
请帮帮我!
public class UploadVideo extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
transferUtility = Util.getTransferUtility(this);
requestWindowFeature(getWindow().FEATURE_NO_TITLE);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.my_activity);
context = this;
new get_people_data().execute();
}
public class get_people_data extends AsyncTask<String,String,String>{
final String TAG = "get_people_data";
String API_URL = "http://api.expressionsapp.com/users/auth0_5732cc152781665b7b5dfee6/status/";
int front;
int behind;
@Override
protected String doInBackground(String...arg0)
{
try
{
JsonParser jParser = new JsonParser();
JSONObject json = jParser.getJSONFromUrl(API_URL);
behind= json.getInt("countBack");
front= json.getInt("countFront");
}catch (JSONException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s)
{
TextView ppl_infront;
TextView ppl_behind;
ppl_infront = (TextView) findViewById(R.id.ppl_infront);
ppl_infront.setText(front);
ppl_behind = (TextView) findViewById(R.id.ppl_behind);
ppl_behind.setText(behind);
}
}
}
【问题讨论】:
-
首先声明
TextView全局部分 -
请显示你的xml
-
在oncreate中初始化textview
-
您应该在
onCreate()中初始化您的小部件并在全局范围内声明它。
标签: android android-layout android-studio android-asynctask