我有这个问题....
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
类(class):
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);
最佳答案
调用对象上的方法意味着调用该对象上的方法;例如,"Hello World".length()
调用 String
上的 length
方法,值为 "Hello World"
。
如错误消息所述,bundle
必须在行 name = bundle.getString("title");
上为 null
,假设那是第 56 行。
如果你勾选the documentation ,当没有使用 putExtras()
向 Intent 添加额外内容时,就会发生这种情况。
关于java - 我有这个错误 :Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54720514/