无法启动活动componentinfo [英] unable to start activity componentinfo

查看:161
本文介绍了无法启动活动componentinfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序不能正常工作,
我有一些与 surfaceviewexample类的问题。
无法启动活动显示java.lang.NullPointerException。
我试图推就tut5按钮,我做了,开始我surfaceview。
是什么原因呢?
我究竟做错了什么?

SurfaceViewExample.java

 公共类SurfaceViewExample扩展活动实现View.OnTouchListener {
    OurView伏;
    位图球;
    浮动的x,y;
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        V =新OurView(本);
        V = setOnTouchListener(本);
        球= BitmapFactory.de codeResource(getResources(),R.drawable.ball);
        X = Y = 0;
        的setContentView(五);
    }    私人OurView setOnTouchListener(SurfaceViewExample surfaceViewExample){
        返回null;
    }
    @覆盖
    保护无效的onPause(){
        super.onPause();
        v.pause();
    }
    @覆盖
    保护无效onResume(){
        super.onResume();
        v.resume();
    }    @覆盖
    公共布尔onTouch(视图V,MotionEvent我){
        返回false;
    }    公共类OurView扩展SurfaceView实现Runnable {
        线程t = NULL;
        SurfaceHolder持有人;
        布尔isItOK = FALSE;        公共OurView(上下文的背景下){
            超级(上下文);
            支架= getHolder();
        }        @覆盖
        公共无效的run()
        {
           而(isItOK ==真)
            {
                如果(!holder.getSurface()。的isValid()){
                    继续;
                }
                帆布C = holder.lockCanvas();
                c.drawARGB(255,150,150,10);
                c.drawBitmap(球,X,Y,NULL);
                holder.unlockCanvasAndPost(C);
            }
        }
        公共无效暂停(){
            isItOK = FALSE;
            而(真){
                尝试{
                    t.join();
                }赶上(InterruptedException的E){
                    e.printStackTrace();
                }
                打破;
            }
            T = NULL;        }
        公共无效简历(){
            isItOK = TRUE;
            T =新的Thread(本);
            t.start();
        }
    }
 }

menu.java

 公共类菜单扩展活动{
    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);
        的setContentView(com.example.youtubeproject.R.layout.activity_main);
        最终的MediaPlayer buttonSound = MediaPlayer.create(菜单。该,
          com.example.youtubeproject.R.raw.button_click);
        按钮TUT1 =(按钮)findViewById(com.example.youtubeproject.R.id.tutorial1);
        按钮tut2 =(按钮)findViewById(com.example.youtubeproject.R.id.tutorial2);
        按钮tut3 =(按钮)findViewById(com.example.youtubeproject.R.id.tutorial3);
        按钮tut4 =(按钮)findViewById(com.example.youtubeproject.R.id.tutorial4);
        按钮tut5 =(按钮)findViewById(com.example.youtubeproject.R.id.tutorial5);
        tut1.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                buttonSound.start();
                的setContentView(com.example.youtubeproject.R.layout.tutorial1);                意图TutorialIntent =新意图(com.example.youtubeproject.TUTORIAL1);
                startActivity(TutorialIntent);                // startActivity(新意图(com.example.youtubeproject.TUTORIAL1));            }
        });        tut2.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                buttonSound.start();
                startActivity(新意图(com.example.youtubeproject.TUTORIALTWO));            }
        });
        tut3.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                buttonSound.start();
                的setContentView(com.example.youtubeproject.R.layout.wallpapaer);
                意向TutorialIntent =新
              意图(com.example.youtubeproject.TUTORIALTHREE);
                startActivity(TutorialIntent);            }
        });
        tut4.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                buttonSound.start();
                意向TutorialIntent =新
            意图(com.example.youtubeproject.TUTORIALFOUR);
                startActivity(TutorialIntent);
               //的setContentView(com.example.youtubeproject.R.layout.wallpapaer);
               //意图TutorialIntent =新
             意图(com.example.youtubeproject.TUTORIALTHREE);
                // startActivity(TutorialIntent);            }
        });
        tut5.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){
                buttonSound.start();
                // startActivity(新意图(com.example.youtubeproject.TUTORIALFIVE));
                意向TutorialIntent =新
          意图(com.example.youtubeproject.TUTORIALFIVE);
               startActivity(TutorialIntent);
                //的setContentView(com.example.youtubeproject.R.layout.wallpapaer);
                //意图TutorialIntent =新
        意图(com.example.youtubeproject.TUTORIALTHREE);
                // startActivity(TutorialIntent);            }
        });
    }    公共布尔onCreateOptionsMenu(菜单菜单)
    {
        super.onCreateOptionsMenu(菜单);
        MenuInflater真棒= getMenuInflater();
        awesome.inflate(com.example.youtubeproject.R.menu.main_menu,菜单);
        返回true;
    }
    公共布尔onOptionsItemSelected(菜单项项){
        开关(项目.getItemId()){
            案例com.example.youtubeproject.R.id.menuSweet:
                startActivity(新意图(com.example.youtubeproject.SWEET));
                返回true;            案例com.example.youtubeproject.R.id.menuToast:                吐司andEggs = Toast.makeText(菜单。该这是敬酒
         Toast.LENGTH_LONG);
                andEggs.show();
                返回true;
        }
        返回false;
    }
}

清单

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
包=com.example.youtubeproject
安卓版code =1
机器人:=的versionName1.0><用途-SDK
    安卓的minSdkVersion =7
    机器人:targetSdkVersion =19/>
<使用许可权的android:NAME =android.permission.SET_WALLPAPER>< /使用许可权>
<应用
    机器人:allowBackup =真
    机器人:图标=@绘制/ ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme>
    <活动
        机器人:名字=。MainActivity
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=android.intent.action.MAIN/>            <类机器人:名字=android.intent.category.LAUNCHER/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动
        机器人:菜单名称=
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=com.example.youtubeproject.MENU/>            <类机器人:名字=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动
    机器人:名字=教程1
    机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
        <作用机器人:名字=com.example.youtubeproject.TUTORIAL1/>        <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
< /活性GT;
    <活动
        机器人:名字=。TutoralTwo
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=com.example.youtubeproject.TUTORIALTWO/>            <类机器人:名字=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动
        机器人:名字=。TutorialThree
        机器人:标签=@字符串/ APP_NAME>
        &所述;意图滤光器>
            <作用机器人:名字=com.example.youtubeproject.TUTORIALTHREE/>            <类机器人:名字=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
    < /活性GT;
    <活动
    机器人:名字=。SurfaceViewExample
    机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
        <作用机器人:名字=com.example.youtubeproject.TUTORIALFIVE/>        <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
< /活性GT;
    <活动
    机器人:名字=。TutorialFour
    机器人:标签=@字符串/ APP_NAME>
    &所述;意图滤光器>
        <作用机器人:名字=com.example.youtubeproject.TUTORIALFOUR/>        <类机器人:名字=android.intent.category.DEFAULT/>
    &所述; /意图滤光器>
< /活性GT;
    <活动        机器人:甜NAME =
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@安卓风格/ Theme.Dialog>
        &所述;意图滤光器>
            <作用机器人:名字=com.example.youtubeproject.SWEET/>            <类机器人:名字=android.intent.category.DEFAULT/>
        &所述; /意图滤光器>
    < /活性GT;
< /用途>   < /清单>


解决方案

声明你 SurfaceViewExample 活动纳入Menifest那样;

 <活动
        机器人:名字=com.example.youtubeproject.SurfaceViewExample>
    < /活性GT;

my program is not working , i have some kind of a problem with the surfaceviewexample class. Unable to start activity java.lang.NullPointerException. i am trying to push on the tut5 button which i made to start my surfaceview. what is the reason for it ? what am i doing wrong ?

SurfaceViewExample.java

    public class SurfaceViewExample extends Activity implements View.OnTouchListener{
    OurView v;
    Bitmap ball;
    float x,y;
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        v=new OurView(this);
        v=setOnTouchListener(this);
        ball= BitmapFactory.decodeResource(getResources(),R.drawable.ball);
        x=y=0;
        setContentView(v);
    }

    private OurView setOnTouchListener(SurfaceViewExample surfaceViewExample) {
        return null;
    }


    @Override
    protected void onPause(){
        super.onPause();
        v.pause();
    }
    @Override
    protected void onResume(){
        super.onResume();
        v.resume();
    }

    @Override
    public boolean onTouch(View v , MotionEvent me) {
        return false;
    }

    public class  OurView extends SurfaceView implements Runnable {
        Thread t=null;
        SurfaceHolder holder;
        boolean isItOK=false;

        public OurView(Context context){
            super(context);
            holder=getHolder();
        }

        @Override
        public void run()
        {
           while (isItOK==true)
            {
                if(!holder.getSurface().isValid()){
                    continue;
                }
                Canvas c=holder.lockCanvas();
                c.drawARGB(255,150,150,10);
                c.drawBitmap(ball,x,y,null);
                holder.unlockCanvasAndPost(c);
            }
        }
        public void pause(){
            isItOK=false;
            while(true){
                try{
                    t.join();
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                break;
            }
            t=null;

        }
        public void resume(){
            isItOK=true;
            t=new Thread(this);
            t.start();
        }
    }
 }

menu.java

 public class menu extends Activity   {


    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView (com.example.youtubeproject.R.layout.activity_main);
        final MediaPlayer  buttonSound = MediaPlayer.create(menu.this,  
          com.example.youtubeproject.R.raw.button_click);
        Button tut1= (Button)findViewById(com.example.youtubeproject.R.id.tutorial1);
        Button tut2= (Button)findViewById(com.example.youtubeproject.R.id.tutorial2);
        Button tut3= (Button)findViewById(com.example.youtubeproject.R.id.tutorial3);
        Button tut4=(Button)findViewById(com.example.youtubeproject.R.id.tutorial4);
        Button tut5=(Button)findViewById(com.example.youtubeproject.R.id.tutorial5);
        tut1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                setContentView (com.example.youtubeproject.R.layout.tutorial1);

                Intent TutorialIntent=new Intent("com.example.youtubeproject.TUTORIAL1");
                startActivity(TutorialIntent);

                //startActivity(new Intent("com.example.youtubeproject.TUTORIAL1"));

            }
        });

        tut2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                startActivity(new Intent("com.example.youtubeproject.TUTORIALTWO"));

            }
        });
        tut3.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                setContentView (com.example.youtubeproject.R.layout.wallpapaer);
                Intent TutorialIntent=new
              Intent("com.example.youtubeproject.TUTORIALTHREE");
                startActivity(TutorialIntent);

            }
        });
        tut4.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                Intent TutorialIntent=new 
            Intent("com.example.youtubeproject.TUTORIALFOUR");
                startActivity(TutorialIntent);
               //setContentView (com.example.youtubeproject.R.layout.wallpapaer);
               //Intent TutorialIntent=new  
             Intent("com.example.youtubeproject.TUTORIALTHREE");
                //startActivity(TutorialIntent);

            }
        });
        tut5.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                buttonSound.start();
                //startActivity(new Intent("com.example.youtubeproject.TUTORIALFIVE"));
                Intent TutorialIntent=new   
          Intent("com.example.youtubeproject.TUTORIALFIVE");
               startActivity(TutorialIntent);
                //setContentView (com.example.youtubeproject.R.layout.wallpapaer);
                //Intent TutorialIntent=new  
        Intent("com.example.youtubeproject.TUTORIALTHREE");
                //startActivity(TutorialIntent);

            }
        });
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
        super.onCreateOptionsMenu(menu);
        MenuInflater awesome=getMenuInflater();
        awesome.inflate(com.example.youtubeproject.R.menu.main_menu,menu);
        return true;
    }
    public  boolean onOptionsItemSelected(MenuItem item){
        switch(item .getItemId()){
            case com.example.youtubeproject.R.id.menuSweet:
                startActivity(new Intent("com.example.youtubeproject.SWEET"));
                return true;

            case com.example.youtubeproject.R.id.menuToast:

                Toast andEggs=Toast.makeText(menu.this,"this is a toast 
         ",Toast.LENGTH_LONG);
                andEggs.show();
                return true;
        }
        return false;
    }
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.youtubeproject"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".menu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.youtubeproject.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
    android:name=".Tutorial1"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.example.youtubeproject.TUTORIAL1" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
    <activity
        android:name=".TutoralTwo"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.youtubeproject.TUTORIALTWO" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".TutorialThree"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.youtubeproject.TUTORIALTHREE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
    android:name=".SurfaceViewExample"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.example.youtubeproject.TUTORIALFIVE" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
    <activity
    android:name=".TutorialFour"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="com.example.youtubeproject.TUTORIALFOUR" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
    <activity

        android:name=".Sweet"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="com.example.youtubeproject.SWEET" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

   </manifest>

解决方案

Declare you SurfaceViewExample activity into Menifest like that;

    <activity
        android:name="com.example.youtubeproject.SurfaceViewExample" >
    </activity>

这篇关于无法启动活动componentinfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆