无法开始新的活动 [英] Can't start new Activity
本文介绍了无法开始新的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
早上好,我尝试从另一个开始新的活动.但是它总是崩溃. 这是我的代码.这是ListView上的事件.
Good day, I try to start new Activity from another. But it always crashed. Here My code. It is the event on ListView.
list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Student selected = (Student)list.getItemAtPosition(position);
String selectedTitle = selected.FirstName; //ideally this would probably be done with accessors
int selectedId = selected.studentId;
String selectedDescription = selected.LastName;
Intent i = new Intent(view.getContext(), StudentInfoActivity.class);
i.putExtra("studentId", selectedId);
try{
startActivity(i);
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
A向清单中添加了一个活动
A added an activity to Manifest
<activity
android:name=".StudentInfoActivity"
android:label="@string/app_name" >
</activity>
错误消息是
06-15 17:17:00.471: E/AndroidRuntime(602): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.marat.mutw/com.marat.mutw.StudentInfoActivity}: java.lang.NullPointerException: uriString
所有以前的活动,我添加的活动都很好...
All previus activities, those I added works fine...
StudentInfoActivity
StudentInfoActivity
public class StudentInfoActivity extends Activity {
ImageView image;
TextView firstLastName;
TextView studentInfo;
TextView addInfo;
Student std;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sudentinfolayout);
image = (ImageView)findViewById(R.id.avatar);
firstLastName = (TextView)findViewById(R.id.firstNameLastName);
studentInfo = (TextView)findViewById(R.id.studentinfo);
addInfo = (TextView)findViewById(R.id.description);
int studentId = getIntent().getExtras().getInt("studentId");
JSONHandler handler = new JSONHandler(this.getApplicationContext());
std = new Student();
std = handler.GetStudentInfo(studentId);
image.setImageURI(Uri.parse(std.imagePath));
firstLastName.setText(std.FirstName+ " "+std.LastName);
}
public void onClickApply(View view){
}
}
推荐答案
而不是
Intent i = new Intent(view.getContext(), StudentInfoActivity.class);
更改为
Create static object of that activity
例如活动actOne = null;
e.g Activity actOne =null;
public static actOne a ;
a = this;
Intent i = new Intent(a, StudentInfoActivity.class);
这篇关于无法开始新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文