java.lang.RuntimeException: Unable to start activity ComponentInfo{com.one.gnuinfo.abcd/com.one.gnuinfo.abcd.ViewActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
引起:java.lang.NullPointerException:尝试在空对象引用上调用虚方法'void android.widget.TextView.setText(java.lang.CharSequence)'
ViewActivity.java代码:
package com.one.gnuinfo.abcd;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RatingBar;
import android.widget.TextView;
public class ViewActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.noticeview);
Bundle bundle = getIntent().getExtras();
String text = bundle.getString("item_text");
TextView sc_t = (TextView) findViewById(R.id.text);
sc_t.setText(text);
if (Build.VERSION.SDK_INT >= 21) {
getWindow().setStatusBarColor(Color.parseColor("#0BC904"));
}
RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar);
TextView textView1 = (TextView)findViewById(R.id.contentview);
TextView textView2 = (TextView)findViewById(R.id.contentview);
TextView textView3 = (TextView)findViewById(R.id.timedateview);
TextView textView4 = (TextView)findViewById(R.id.inquiryview);
bundle = getIntent().getExtras();
Float score = bundle.getFloat("score");
String time = bundle.getString("time");
String content = bundle.getString("content");
String timestap = bundle.getString("timestap");
String inquiry = bundle.getString("inquiry");
ratingBar.setRating(score);
textView1.setText(time);
textView2.setText(content);
textView3.setText(timestap);
textView4.setText("inquiry "+inquiry);
}
}