Question

I'm creating an android application that can play the video from xml file in ListView. But somehow when I clicked on the ListView, the error message come out and the application is forcing to stop.

The listview code is

public class CustomizedListView extends Activity {    
static final String URL = "...";

static final String KEY_LINK = "link";


@Override
public void onItemClick(AdapterView<?> parent, View view,
 int position, long id) {

String  myUrl = channelList.get(position).get("url");
Intent n = new Intent(CustomizedListView.this , VideoViewActivity.class);
      n.putExtra("url", myUrl);
      startActivity(n);

VideoView code:

public class VideoViewActivity extends Activity {

Intent n = getIntent();

String myurl = n.getStringExtra("url");
VideoView videoView;

@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.videoview_main);
   
 videoView = (VideoView) findViewById(R.id.VideoView);
 MediaController mc = new MediaController(this);
 videoView.setMediaController(mc);

 Uri video = Uri.parse(myurl);
 videoView.setVideoURI(video);

 videoView.requestFocus();
 videoView.start();
 }

 }

I tried to change the static final String KEY_LINK = "link"; to static final String KEY_LINK = "videolocation"; as suggested on other post but it still doesn't work.

The crash log are:

 E/Trace(29679): error opening trace file: No such file or directory (2)
 E/AndroidRuntime(29679): FATAL EXCEPTION: main
 E/AndroidRuntime(29679): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.androidhive/com.example.androidhive.VideoViewActivity}; have you declared this activity in your AndroidManifest.xml?
 E/AndroidRuntime(29679):  at : E/AndroidRuntime(29679):  at  android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
 E/AndroidRuntime(29679):  at android.app.Activity.startActivityForResult(Activity.java:3351)
 E/AndroidRuntime(29679):  at android.app.Activity.startActivityForResult(Activity.java:3312)
 E/AndroidRuntime(29679):  at android.app.Activity.startActivity(Activity.java:3522)
 E/AndroidRuntime(29679):  at android.app.Activity.startActivity(Activity.java:3490)
 E/AndroidRuntime(29679):  at com.example.androidhive.CustomizedListView$1.onItemClick(CustomizedListView.java:85)
 E/AndroidRuntime(29679):  at android.widget.AdapterView.performItemClick(AdapterView.java:298)
 E/AndroidRuntime(29679):  at android.widget.AbsListView.performItemClick(AbsListView.java:1102)
 E/AndroidRuntime(29679):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2945)
 E/AndroidRuntime(29679):  at android.widget.AbsListView$1.run(AbsListView.java:3629)
 E/AndroidRuntime(29679):  at android.os.Handler.handleCallback(Handler.java:615)
 E/AndroidRuntime(29679):  at android.os.Handler.dispatchMessage(Handler.java:92)
 E/AndroidRuntime(29679):  at android.os.Looper.loop(Looper.java:137)
 E/AndroidRuntime(29679):  at android.app.ActivityThread.main(ActivityThread.java:4794)
 E/AndroidRuntime(29679):  at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(29679):  at java.lang.reflect.Method.invoke(Method.java:511)
 E/AndroidRuntime(29679):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
 E/AndroidRuntime(29679):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
 E/AndroidRuntime(29679):  at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

you have not declared VideoViewActivity activity in your manifest. please declare it in manifest and then try.

the logcat shows

android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.androidhive/com.example.androidhive.VideoViewActivity}; have you declared this activity in your AndroidManifest.xml?

in manifest file under application tag write

 <activity android:name=".VideoViewActivity ">
 </activity>

move this after setContentView in video view activity

Intent n = getIntent();
String myurl = n.getStringExtra("url");

OTHER TIPS

The problem because you haven't register your VideoViewActivity in your manifest file. So register under application tag it by

<activity android:name=".VideoViewActivity ">
</activity>

you should move this

 Intent n = getIntent();

 String myurl = n.getStringExtra("url");

after onCreate() method. SO it will be

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.videoview_main);


  Intent n = getIntent();
  String myurl = n.getStringExtra("url");
  videoView = (VideoView) findViewById(R.id.VideoView);
  MediaController mc = new MediaController(this);
  videoView.setMediaController(mc);

  Uri video = Uri.parse(myurl);
  videoView.setVideoURI(video);

  videoView.requestFocus();
  videoView.start();
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top