我遇到了这个问题。...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
at com.nacxo.darshansoni.team_prediction.HalaplayMatches.onCreate(HalaplayMatches.java:56)
at android.app.Activity.performCreate(Activity.java:6974)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2900)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3012)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1716)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:232)
at android.app.ActivityThread.main(ActivityThread.java:6802)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1103)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
这是我的Halaplaymatches
班:
public class HalaplayMatches extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
private String name;
TextView descriptionhala,e_advicehala,visit;
ImageView imageView,imageView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_halaplay_matches);
Bundle bundle=getIntent().getExtras();
name = bundle.getString("title");
visit=findViewById(R.id.hmustVisit);
// e_advicehala=findViewById(R.id.advicehalaplay);
descriptionhala=findViewById(R.id.deschalaplay);
答案 0 :(得分:0)
您可以这样操作。在为名称分配值之前,请检查捆绑软件中是否包含密钥“ title”
if (getIntent() != null) {
if (getIntent().getExtras() != null) {
Bundle bundle = getIntent().getExtras();
if (bundle.containsKey("title")) {
if (!TextUtils.isEmpty(bundle.getString("title")) && bundle.getString("title") != "")
name = bundle.getString("title");
}
}
}
答案 1 :(得分:0)
调用对象上的方法意味着调用该对象上的方法;例如,"Hello World".length()
在length
上使用值String
调用"Hello World"
方法。
如错误消息所述,bundle
必须在null
行的name = bundle.getString("title");
上,假设是第56行。
如果您选中the documentation,则会在没有使用putExtras()
向意图添加任何额外内容时发生这种情况。