Android 单击按钮开始';s安卓应用程序不是';t运行:

Android 单击按钮开始';s安卓应用程序不是';t运行:,android,button,onclicklistener,Android,Button,Onclicklistener,我是新来的,发布了我的第一个问题。所以这个关于点击按钮显示布局的android项目没有运行。当我运行它时,模拟器会打开,但我的项目在上面不可见。我试图在点击按钮时显示另一个布局。有人能帮我吗? 我的布局是:活动\主、教程1(单击按钮:教程1后显示的布局)、splash(打开时显示5秒钟)。 此外,manja是开场时播放的声音的名称,持续5秒。 这是我的密码: MainActivity.java: package com.example.thebasics; import android.app

我是新来的,发布了我的第一个问题。所以这个关于点击按钮显示布局的android项目没有运行。当我运行它时,模拟器会打开,但我的项目在上面不可见。我试图在点击按钮时显示另一个布局。有人能帮我吗? 我的布局是:活动\主、教程1(单击按钮:教程1后显示的布局)、splash(打开时显示5秒钟)。 此外,manja是开场时播放的声音的名称,持续5秒。 这是我的密码: MainActivity.java:

package com.example.thebasics;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;



public class MainActivity extends Activity {

 MediaPlayer logoMusic;
    @Override
    protected void onCreate(Bundle AmanIsAwesome) {
        super.onCreate(AmanIsAwesome);
        setContentView(R.layout.splash);
        logoMusic = MediaPlayer.create(MainActivity.this, R.raw.manja);
        logoMusic.start();

        Thread logoTimer= new Thread (){
         public void run (){
             try{
                 sleep(5000);
                 Intent menuIntent=new Intent("com.example.thebasics.MENU");
                 startActivity(menuIntent);
             } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             finally{
                   finish();
             }
         }
        };
        logoTimer.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        logoMusic.release();
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
Menu.java:

package com.example.thebasics;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;


public class menu extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button tut1 = (Button) findViewById(R.id.tutorial1);
        tut1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent ("com.example.thebasics.TUTORIAL"));
            }
        });
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
    }

}
Tutorial.java:

       package com.example.thebasics;

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

public class Tutorial extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tutorial1);
    }

}
    }
基本androidmanifest:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/download"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.thebasics.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />

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

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

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

    </application>

</manifest>

控制台还显示错误:-Emulator[警告:未找到DNS服务器] 这是什么?

用这个代替:

startActivity(new Intent (context, Tutorial.class));
你的做法也很奇怪:

不要这样做:

<activity
        android:name="com.example.thebasics.TUTORIAL"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.thebasics.TUTORIAL" />

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

只要做:

<activity
        android:name="com.example.thebasics.Tutorial"
        android:label="@string/app_name" >

 </activity> 

另一个也一样

这是不存在的:

<action android:name="com.example.thebasics.TUTORIAL" />

此行代码

new Intent ("com.example.thebasics.TUTORIAL")
使用操作名“com.example.thebasics.TUTORIAL”创建

你想要的是:

startActivity(new Intent (MainActivity.this, Tutorial.class));
就像Tsunaze建议的那样。

按如下操作

Intent intent = new Intent(context, Tutorial.class);
// set some flags here according to your need
startActivity(intent);

Intent intent = new Intent(context, Menu.class);
// set some flags here according to your need
startActivity(intent);
并将其从清单文件中删除,因为这是错误的

<intent-filter>
            <action android:name="com.example.thebasics.MENU" />

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


<intent-filter>
            <action android:name="com.example.thebasics.TUTORIAL" />

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

我已经上传了您项目的完整工作。请从下载。也请使用其他人提到的意图

  Intent intent = new Intent(MainActivity.this or getApplicationContext(), Tutorial.class);
  /* First argument is your current activity.You can also mention it i.e CurrentActivity.this */
  /* Second argument is the class where you wanna go i.e OtherActivity.class */
  startActivity(intent); 

在menu.java和tutorial.java中,您提到了相同的代码…布局相同…也发布tutorial.java代码我已经发布并更改了意图,删除了action android:name字段,发布了tutorial.java代码,我的项目显示在模拟器上,但启动屏幕后显示“意外停止”错误,你给的项目,crunch文件夹中的res有一些错误,我不知道如何修复,因为我对安卓系统是全新的!:)只需清理这个项目并再次运行它..它已完成:)首先,你太棒了!但是,你能告诉我我犯了哪些错误以及你添加了哪些新内容来实现这一点吗?谢谢。首先,你使用了错误的意图……其次,你在manifest.xml中错误地提到了活动。第三,你在多个活动中使用了相同的布局。干杯:)你好,谢谢你的帮助,我已经按照你的建议进行了更改,现在我的项目在emulator上可见,但在显示启动屏幕5秒后,它显示“Thebasics意外停止”错误。请帮助。。。!!哦谢谢但请告诉我为什么我们要从清单中删除这些意图行过滤器?以及何时使用它们?我们没有?阅读这些文档,如果答案有助于您,请接受并投票:)