user1200699
user1200699

Reputation: 13

fatal exception: main caused by java.lang.NullPointerException menu button

I am brand new on Android. I tried to set up menu button and met this problem. I checked on this forum about this and found it means that something not defined, but couldn't figure out which one in my code left undefined. Please help! Any suggestions would be greatly appreciated.

By the way, Camera_SettingActivity.java works fine if I run it separately.

public class VideoViewActivity extends Activity {

    protected int my_num = 2280;
    protected Intent intent_camera;

    /** Called when the activity is first created. */
            @Override
            public boolean onCreateOptionsMenu(Menu menu) {
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.layout.menu, menu);
                return true;
            }

            @Override
            public boolean onOptionsItemSelected(MenuItem item) {

                intent_camera = new Intent();

                switch (item.getItemId()) {

                    case R.id.camera:
                        intent_camera.setClass(VideoViewActivity.this, Camera_SettingActivity.class);
                        startActivityForResult(intent_camera, my_num);
                        break;

                }
                return true;
            }

}



public class Camera_SettingActivity extends Activity {


protected int my_num = 1228;
private Bundle bundle;

public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
private VideoView videoView1 = null;
private Context ctx = null;
private ProgressBar prog1 = null;

protected String str_IP;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_camera_layout);

    bundle = this.getIntent().getExtras();

    str_IP = bundle.getString("editIP");

    Button test1 = (Button) findViewById(R.id.button_test1);

    test1.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View v) {

            prog1 = (ProgressBar)findViewById(R.id.progressBar1);
                    videoView1  = (VideoView) findViewById(R.id.videoView1);
                    Uri video   = Uri.parse(url);

                    videoView1.setVideoURI(video);

                    videoView1.setOnErrorListener(new OnErrorListener() {

                        @Override
                        public boolean onError(MediaPlayer mp, int what, int extra) {
                            // TODO Auto-generated method stub
                            Toast.makeText(ctx, "Error occured", 500).show();
                            return false;
                        }
                    });

                    videoView1.setOnPreparedListener(new OnPreparedListener() {

                        public void onPrepared(MediaPlayer arg0) {
                            prog1.setVisibility(View.GONE);
                            videoView1.start();
                        }
                    });
             }

    });
}

 @Override
 protected void onDestroy() {
     try{
         videoView1.stopPlayback();
     }catch(Exception e){
         //
     }
     super.onDestroy();
 }

}

Upvotes: 0

Views: 1581

Answers (1)

kosa
kosa

Reputation: 66637

Every activity should have onCreate() method. Your code missing it. Which might be causing error. Add onCreate() and setContentView() inside the method.

Upvotes: 1

Related Questions