[英]Attempt to invoke virtual method '…' on null object Reference
I have problem with my App ,, and want to solve it but i could not access to solution please help me ,,, 我的应用程序有问题,并想解决它,但是我无法获得解决方案,请帮助我,,,
// Main_Activity Class
public class MainActivity extends Activity {
Button Open_play_list;
AccessPlayList accessPL;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Open_play_list = (Button)findViewById(R.id.btnShA);
accessPL = new AccessPlayList();
Open_play_list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Calling method tht contain code for open playlist
try {
accessPL.openPlaylist();
}`enter code here`
catch (Exception ex) {
Toast.makeText(getBaseContext(), ex.getMessage().toString(), Toast.LENGTH_LONG).show();
}
}
});
}
// AccessPlayList Class
public class AccessPlayList extends Activity {
Intent intentPL;
int REQUEST_CODE = 1;
int PLAYLIST_ID = 2;
public void openPlaylist()
{
intentPL = new Intent(Intent.ACTION_PICK);
intentPL.setComponent(new ComponentName("com.android.music","com.android.music.PlaylistBrowserActivity"));
intentPL.setType("MediaStore.Audio.Playlist.CONTENT_TYPE");
intentPL.setFlags(0x10000000);
intentPL.putExtra("oneShot",false);
intentPL.putExtra("PlayList",PLAYLIST_ID);
startActivityForResult(intentPL,REQUEST_CODE);
}
}
Since you did not post which line of your code is where the error is occurring, the only thing I can tell you is that you need to check if the object causing the problem is null. 由于您没有发布发生错误的代码行,因此我唯一可以告诉您的是,您需要检查导致问题的对象是否为null。 Try some validation like this:
尝试这样的验证:
if(object != null){
//do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.