为什么这不完全运行?

时间:2013-12-04 03:23:14

标签: android surfaceview

这是来自mybringback的线程教程的一点表面视图。在这一点上,它应该只打开一个颜色在其中的窗口。我没有任何错误,但是当我在模拟器或我自己的平板电脑上运行它时,应用程序会打开,然后在它关闭时给出错误。

import android.app.Activity;
import android.os.Bundle;


public class GFXSurface extends Activity{

MySurface mySurface;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mySurface = new MySurface(this);
        setContentView(mySurface);
    }   


    }

这是第二个:

import android.content.Context;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
import android.view.SurfaceView;


public class MySurface extends SurfaceView implements Runnable{

    SurfaceHolder holder;
    Thread thread = null;
    boolean isRunning = true;

    public MySurface(Context context) {
    super(context);
    holder = getHolder();
    thread = new Thread(this);
    thread.start();
    }

    @Override
    public void run() {
    while(isRunning){
        if(!holder.getSurface().isValid())
            continue;
        Canvas canvas = holder.lockCanvas();
        canvas.drawRGB(02, 02, 150);
        holder.unlockCanvasAndPost(canvas);
        }

        }

    }

这是我的清单,以确保我正确注册

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gfxsurface"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.gfxsurface.GFXSurface"
        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>

无论如何,我早期的应用程序在mybringback中运行得很好,但是这个没有做到。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

更改以下行:

super.onCreate(savedInstanceState);

        setContentView(R.Layout.mySurface);
mySurface = new MySurface(this);