我正在尝试运行Pro Android Media一书中的应用程序来了解流的功能。但是,发生以下错误:
12-26 16:32:31.464: E/AndroidRuntime(508): FATAL EXCEPTION: main
12-26 16:32:31.464: E/AndroidRuntime(508): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.streaming/com.example.streaming.Streaming}: java.lang.ClassNotFoundException: com.example.streaming.Streaming in loader dalvik.system.PathClassLoader[/data/app/com.example.streaming-2.apk]
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.os.Looper.loop(Looper.java:123)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-26 16:32:31.464: E/AndroidRuntime(508): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 16:32:31.464: E/AndroidRuntime(508): at java.lang.reflect.Method.invoke(Method.java:521)
12-26 16:32:31.464: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 16:32:31.464: E/AndroidRuntime(508): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 16:32:31.464: E/AndroidRuntime(508): at dalvik.system.NativeStart.main(Native Method)
12-26 16:32:31.464: E/AndroidRuntime(508): Caused by: java.lang.ClassNotFoundException: com.example.streaming.Streaming in loader dalvik.system.PathClassLoader[/data/app/com.example.streaming-2.apk]
12-26 16:32:31.464: E/AndroidRuntime(508): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
12-26 16:32:31.464: E/AndroidRuntime(508): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
12-26 16:32:31.464: E/AndroidRuntime(508): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-26 16:32:31.464: E/AndroidRuntime(508): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
12-26 16:32:31.464: E/AndroidRuntime(508): ... 11 more
12-26 16:51:14.974: D/AndroidRuntime(1433): Shutting down VM
12-26 16:51:15.054: W/dalvikvm(1433): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
代码:
ViewTheVideo
package com.example.streaming;
import com.example.streaming.R;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class ViewTheVideo extends Activity {
VideoView vv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vv = (VideoView) this.findViewById(R.id.VideoView);
Uri videoUri = Uri.parse("rtsp://v2.cache2.c.youtube.com/CjgLENy73wIaLwm3JbT_� 9HqWohMYESARFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg _vSmsbeSyd5JDA==/0/0/0/video.3gp");
vv.setMediaController(new MediaController(this));
vv.setVideoURI(videoUri);
vv.start();
}
}
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<VideoView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/VideoView">
</VideoView>
</LinearLayout>
的AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.streaming"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name = ".Streaming"
android:label = "@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我会等待我的问题的答案。
谢谢你们!
答案 0 :(得分:3)
更改
public class ViewTheVideo extends Activity {
//....your code here
到
public class Streaming extends Activity {
//....your code here
因为您将AndroidManifest
中的活动声明为.Streaming
,但在java类名称中为ViewTheVideo
或强>
您也可以将AndroidManifest
中的名称更改为:
<activity android:name = ".ViewTheVideo"
android:label = "@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name = "android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>