有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java代码阻止应用程序打开?

我的代码是否阻止我的应用打开?没有错误,但是它没有打开。或者分割字符串是否存在导致冲突的问题

main活动:

package com.pk.code;

import 安卓.app.Activity;
import 安卓.os.Bundle;
import 安卓.view.Menu;
import 安卓.widget.TextView;

public class MainActivity extends Activity {

    TextView smsText;@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        smsText = (TextView) findViewById(R.id.smsText);

        Bundle extra = getIntent().getExtras();
        if (extra != null) {
            String SMSText = extra.get("sms").toString();
            String[] splitted = SMSText.split("-");
            if (splitted.length > 1 && splitted.length < 4) {
                smsText.setText(" " + splitted[0] + "," + " " + splitted[1]);
            } else {
                smsText.setText(SMSText);


            }
        }
    }


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

共 (1) 个答案

  1. # 1 楼答案

    很可能是额外的问题。get(“sms”),它返回null。崩溃后,检查日志并在此处打印