【问题标题】:launching my android app shows error log cat is not helping?启动我的 android 应用程序显示错误日志 cat 没有帮助?
【发布时间】:2015-11-08 23:32:38
【问题描述】:

我是初学者。每当我尝试启动我的 android 应用程序时,它都会显示错误 unfortunately my app has been stopped 。现在让我具体一点,我创建了一个推送机器人应用程序来获取通知并通过将其转换为字符串来在 textview 上显示它。它在通知到达时完美运行,当我单击通知时,它将在屏幕上显示字符串,但在我启动它时不会。在 deadfish 说它可能会发生之前,我问了一个问题,因为我的包是空的,所以我尽我所能为我正在显示字符串的 textview 提供一个临时字符串。但它仍然显示错误。当我启动我的应用程序时,我会向你展示 logcat。我认为空包不是问题

08-16 08:58:06.868  13447-13454/com.bluestacks.chartapp I/jdwp﹕ Ignoring second debugger -- accepting and dropping

公共类 MainActivity 扩展 ActionBarActivity {

public static final String TAG = MainActivity.class.getSimpleName();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Pushbots.sharedInstance().init(this);
    Intent intent = getIntent();


    //log the message in JSON format
    Log.i(TAG, "Received message >> " + intent.getExtras().toString());
    //Retrieve message and extra
    String message = intent.getExtras().getString("message");
    TextView t1 = (TextView)findViewById(R.id.textView);
    if(message!=null) {
        t1.setText(message);
    }
    else
    {
        t1.setText("null");
    }

    Bundle extras = intent.getExtras();
    String bigText = null;
    TextView t2 = (TextView) findViewById(R.id.textView2);
    if (extras != null && extras.containsKey("bigText")) {
        bigText = extras.getString("bigText");
        t2.setText(bigText);
    }
    else{
        t2.setText("null");
    }

}





@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

【问题讨论】:

  • 当您的应用程序崩溃时,从 logcat 发布完整的堆栈跟踪。
  • 字符串消息 = intent.getExtras().getString("message"); Intent 可以为 null 确保在尝试获取额外信息之前检查 Intent 是否为 null

标签: java android xml android-layout


【解决方案1】:

您的bundenull,因此您的应用将在此行强制关闭:

Log.i(TAG, "Received message >> " + intent.getExtras().toString());

试试这个:

String message = null;

  //log the message in JSON format
    Log.i(TAG, "Received message >> " + intent.getExtras());
    //Retrieve message and extra
    message = intent.getStringExtra("message");
    TextView t1 = (TextView)findViewById(R.id.textView);
    if(message!=null) {
        t1.setText(message);
    }
    else
    {
        t1.setText("null");
    }

【讨论】:

  • 效果很好......还有一个问题(-.-)/该死的!!!!你们是什么人??编程之神???
  • 不,只是前段时间和你一样的人:)
猜你喜欢
  • 2014-01-26
  • 2011-05-19
  • 2018-04-01
  • 2017-04-17
  • 2013-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多