2012-06-15 114 views
0

美好的一天,我嘗試從另一個開始新的活動。但它總是墜毀。 這裏我的代碼。這是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(); 
       } 

      } 
     }); 

一個加入活動的體現

<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 

所有previus活動,我的那些作品加精...

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){ 

    } 

} 
+0

你可以發佈你的oncreate的StudentInfoActivity? – jsb

+0

問題出在StudentInfoActivity.java上請提供 –

+0

這裏有什麼'uriSting'?並且,發佈你的'StudentInfoActivity.java' – Praveenkumar

回答

1

代替

Intent i = new Intent(view.getContext(), StudentInfoActivity.class); 

變化到

Create static object of that activity 

e.g活動actOne = NULL;

public static actOne a ; 
a = this; 

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

謝謝,它有助於=) – nabiullinas

0

試試這個。

Intent i = new Intent(getApplicationContext(), StudentInfoActivity.class); 
i.putExtra("studentId", selectedId); 
startActivity(i);