简体   繁体   English

尝试在空对象参考上调用虚拟方法“…”

[英]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.

相关问题 尝试在 null object 参考上调用虚拟方法... - Attempt to Invoke virtual method ... on a null object reference 尝试在空对象引用上调用虚拟方法 - Attempt to invoke virtual method on a null object reference 尝试调用虚方法 - 空对象引用 - Attempt to invoke virtual method - Null object reference 尝试在空对象引用上调用虚拟方法“…………” - Attempt to invoke virtual method '.........' on a null object reference 尝试对空对象引用调用虚拟方法“” - Attempt to invoke virtual method ' 'on a null object reference 尝试在空对象引用上调用虚拟方法 - Attempt to invoke virtual method on a null object reference 尝试在空对象引用上调用虚拟方法,但对象不为空 - Attempt to invoke virtual method on a null object reference but the object is not null 尝试在null对象引用上调用虚拟方法android.widget.EditText.getText() - Attempt to invoke virtual method on Attempt to invoke virtual method android.widget.EditText.getText() on a null object reference QUICKBLOX尝试在空对象引用上调用虚方法sendMessage - QUICKBLOX Attempt to invoke virtual method sendMessage on null object reference Android尝试在空对象引用上调用虚拟方法“…” - Android Attempt to invoke virtual method '…' on a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM