Here is my PlayerActivity:
package player.org;
import android.app.开发者_如何转开发Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.app.Activity;
import android.os.Bundle;
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media=new MediaView(this);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
}
}
here is my MediaView:
package player.org;
import android.app.Activity;
import android.view.*;
import android.widget.ImageView;
import android.content.*;
import android.content.*;
import android.graphics.Color;
class MediaView extends View
{
public MediaView(Context context)
{
super(context);
setBackgroundColor(Color.WHITE);
}
}
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="player.org"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity
android:name=".MediaView"
android:label="@string/MediaView_title">
</activity>
<activity android:name=".PlayerActivity"
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>
But when I Launch the app., It force closes.
Do you have any suggestions? Thanks for your answers
You are writing this line private MediaView media=new MediaView(this);
,before the Activity is initiated.So 'this'
keyword is force closing your application
Please use like this
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
media=new MediaView(this);
}
}
精彩评论