Android 更新TextView会导致即时崩溃
我正在使用类中的方法更新textView,当我运行应用程序时,会出现以下错误:Android 更新TextView会导致即时崩溃,android,Android,我正在使用类中的方法更新textView,当我运行应用程序时,会出现以下错误: A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) 我已经看了关于stackoverflow的另一个问题,但这是另一种类型的程序,它涉及一个webview,因此没有太大帮助。我尝试使用调试器查找错误,但它还是崩溃了。 这是我主要活动的代码: protected void onPostExecute(String s) { super.on
A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL)
我已经看了关于stackoverflow的另一个问题,但这是另一种类型的程序,它涉及一个webview,因此没有太大帮助。我尝试使用调试器查找错误,但它还是崩溃了。这是我主要活动的代码:
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
JSONObject jsonObject = new JSONObject(s);
dati.status = jsonObject.getString("status");
dati.totalResults = jsonObject.getInt("totalResults");
String articles = jsonObject.getString("articles");
JSONArray arr = new JSONArray(articles);
for(int i=0;i<arr.length();i++){
JSONObject jsonPart = arr.getJSONObject(i);
String source = jsonPart.getString("source");
JSONObject jsonPart2 = new JSONObject(source);
Source s1 = new Source(jsonPart2.getString("id"),jsonPart2.getString("name"));
dati.articoli.put(i, new Article(s1,jsonPart.getString("author"),jsonPart.getString("title"),
jsonPart.getString("description"),jsonPart.getString("url"),jsonPart.getString("urlToImage"),jsonPart.getString("publishedAt"),
jsonPart.getString("content")));
}
}catch (Exception e){
e.printStackTrace();
}
dati.stampaDati(0,txt_articolo,txt_contatore);
}
受保护的void onPostExecute(字符串s){
super.onPostExecute(s);
试一试{
JSONObject JSONObject=新的JSONObject;
dati.status=jsonObject.getString(“状态”);
dati.totalResults=jsonObject.getInt(“totalResults”);
stringarticles=jsonObject.getString(“articles”);
JSONArray arr=新JSONArray(文章);
对于(int i=0;i将此Integer.toString(this.totalResults)
更改为String.valueOf(totalResults)
而且在textView.setText()中不应该有字符串连接
例如
public class Dati {
public String status;
public int totalResults;
public ArrayMap<Integer,Article> articoli = new ArrayMap<Integer, Article>();
public void stampaDati(int articoloCorrente, TextView txt_articolo,TextView txt_contatore){
Log.i("asd",Integer.toString(this.totalResults));
txt_contatore.setText("articolo "+(articoloCorrente+1)+" di "+Integer.toString(this.totalResults));
txt_articolo.setText("Autore:"+articoli.get(articoloCorrente).sourceA.name);
}}
String displayStr1 = "articolo "+(articoloCorrente+1)+" di "+ String.valueOf(this.totalResults);
txt_contatore.setText(displayStr1);
String displayStr2 = "Autore:"+articoli.get(articoloCorrente).sourceA.name;
txt_articolo.setText(displayStr2)