java - 无法启动新 Activity

标签 java android android-activity

美好的一天,我尝试从另一个开始新的 Activity 。但总是崩溃。 这是我的代码。这是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 向 Manifest 添加了一个 Activity

<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

所有以前的 Activity ,我添加的都工作正常......

学生信息 Activity

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 

例如 Activity actOne =null;

public static actOne a ;
a = this;

Intent i = new Intent(a, StudentInfoActivity.class);

关于java - 无法启动新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11047916/

相关文章:

java - 安卓设置 fragment

Java编译器返回null

java - Spring 安全: deserialize request body twice (oauth2 processing)

java - A* (A Star) 算法输出所有可能的解决方案

android - 如何自动化向 Android Activity 发送多个模拟 Intent 的测试?

android - 当我尝试运行该应用时会崩溃但没有错误? (Android Studio)

java - 终止期间线程延迟

java - Android ADT 插件无法在 Eclipse 上打开 XML 文件

iphone - Android 中 TouchXML 的等效解析器是什么?

android - 无法设置 PagerAdapter 类型?怎么了?