故障排除 - 活动启动

发布于 2025-01-08 13:06:18 字数 3421 浏览 0 评论 0原文

我在开始活动时遇到错误,到目前为止我一直无法找到解决方案,是否有人可以帮助我对代码进行故障排除?

SPLASH:

package inno.games;

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

public class Splash extends Activity{
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle Jonas) {
    // TODO Auto-generated method stub
    super.onCreate(Jonas);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);

            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent introscreenactivity = new Intent("Inno.Games.INTROSCREEN");
                startActivity(introscreenactivity);
            }
        }
    };
    timer.start();
}
@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}


}

初始化下一个活动时出现错误。

下一个活动的代码 (我想在单击按钮时启动一个新活动)

package inno.games;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

public class Introscreen extends Activity {


Button proceed;

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


proceed = (Button) findViewById(R.id.bProceed);
proceed.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {

        Intent myIntent = new Intent(Introscreen.this, BillardScoreboardActivity.class);
        Introscreen.this.startActivity(myIntent);

    }
}); 
}

这是我的清单:

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

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <activity
        android:name=".Splash"
        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=".Intro"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="Inno.Games.INTROSCREEN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

      <activity
        android:name=".BillardScoreboardActivity"
        android:label="@string/app_name" >
    </activity>

    </application>

SPLASH 是 obv 启动屏幕 IINTROSCREEN 是启动后的活动 BILLARDSCOREBOARDACTIVITY 是我想在屏幕 GUI 上单击按钮时启动的活动。

I'm getting errors upon start of my activities, and i've been unable to find the solution so far, is there by any chance anyone who could help me troubleshooting my code?

SPLASH:

package inno.games;

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

public class Splash extends Activity{
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle Jonas) {
    // TODO Auto-generated method stub
    super.onCreate(Jonas);
    setContentView(R.layout.splash);
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
    ourSong.start();
    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(5000);

            } catch (InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent introscreenactivity = new Intent("Inno.Games.INTROSCREEN");
                startActivity(introscreenactivity);
            }
        }
    };
    timer.start();
}
@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
    finish();
}


}

An error appears upon initialization of the next activity.

CODE FOR NEXT ACTIVITY
(which i want to start a new activity on buttonclick)

package inno.games;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

public class Introscreen extends Activity {


Button proceed;

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


proceed = (Button) findViewById(R.id.bProceed);
proceed.setOnClickListener(new OnClickListener() {

    public void onClick(View v) {

        Intent myIntent = new Intent(Introscreen.this, BillardScoreboardActivity.class);
        Introscreen.this.startActivity(myIntent);

    }
}); 
}

THIS IS MY MANIFEST:

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

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <activity
        android:name=".Splash"
        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=".Intro"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="Inno.Games.INTROSCREEN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

      <activity
        android:name=".BillardScoreboardActivity"
        android:label="@string/app_name" >
    </activity>

    </application>

SPLASH is obv splash screen
IINTROSCREEN is the activity following splash
And BILLARDSCOREBOARDACTIVITY is the activity i want to start uppon buttonclick on introscreen GUI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天冷不及心凉 2025-01-15 13:06:19

将清单文件中的活动名称更改

android:name=".Intro"

android:name=".Introscreen "

change your activity name in your Manifest file

android:name=".Intro"

into

android:name=".Introscreen "
空‖城人不在 2025-01-15 13:06:18

您需要更正这部分:

<activity
        android:name=".Intro"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="Inno.Games.INTROSCREEN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

使用以下内容:

<activity
        android:name=".Introscreen"
        android:label="@string/app_name" >
  </activity>

实际上有什么问题?
您尚未使用您创建的活动的确切名称来声明活动。您只给出了 .Intro 而不是 .Introscreen

You need to correct this part:

<activity
        android:name=".Intro"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="Inno.Games.INTROSCREEN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

with this:

<activity
        android:name=".Introscreen"
        android:label="@string/app_name" >
  </activity>

What is wrong actually?
You haven't declared activity with its exact name that you have created. You have given only .Intro instead of .Introscreen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文