2

我正在尝试运行 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)

代码:

观看视频

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();
} 

}

主.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>

我将等待我的问题的答案。

多谢你们!

4

1 回答 1

3

改变

public class ViewTheVideo extends Activity {
//....your code here

public class Streaming extends Activity {
//....your code here

因为您在AndroidManifestas中声明 Activity.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>
于 2012-12-26T20:26:34.860 回答