新手Android麻烦:app打开错误的main.xml?

时间:2011-08-31 16:14:13

标签: java android eclipse

我刚刚开始Android开发,所以请耐心等待。

我的问题是,当我在模拟器中运行我的应用程序时,在我的启动画面之后,弹出的下一个屏幕来自与我正在使用的应用程序完全不同的应用程序。两个屏幕冲突的名称相同(主屏幕) .xml)这可能与它有关但它们在完全不同的文件夹和工作区中。我一直试图尝试使用我的代码在我的启动画面完全显示之后停止屏幕,这样我就可以更好地了解问题发生的位置但是没有成功。

有没有人知道可能出现什么问题,或者我至少应该开始寻找解决这个问题的地方?

日食中的

文件: http://imgur.com/kORdH

主要活动类:

package com.mwmnj.criticmatch;

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

public class CriticMatchActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);    
    }
}

main.xml中:

<?xml version="1.0" encoding="utf-8" ?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:padding="20dp"
    android:weightSum="1">
    <TextView android:textAppearance="?android:attr/textAppearanceLarge"
        android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Hello!"
        android:layout_gravity="center" />
    <TextView android:textAppearance="?android:attr/textAppearanceMedium"
        android:id="@+id/textView2" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="criticmatch">android:layout_gravity="center"></TextView>
    <Button android:text="Proceed" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:id="@+id/button1"
        android:layout_marginTop="50dp" />
</LinearLayout>

启动课程

package com.mwmnj.criticmatch;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        Thread timer = new Thread(){
            public void run(){
                try{
                    sleep(5000);
                } catch (InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent openStartingPoint = new Intent("matt.meyer.criticmatch.MENU");
                    startActivity(openStartingPoint);
                }
            }
        };
        timer.start();
    }
}

splash.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@drawable/crbackground"
  >


</LinearLayout>

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mwmnj.criticmatch"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" 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=".CriticMatchActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="com.mwmnj.criticmatch.CRITICMATCHACTIVITY"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

    </application>
</manifest>

2 个答案:

答案 0 :(得分:0)

你的问题在这里:

Intent openStartingPoint = new Intent("matt.meyer.criticmatch.MENU");
startActivity(openStartingPoint);

据我所知,这指向了其他一些应用程序。试试这个:

Intent openStartingPoint = new Intent(Splash.this, CriticMatchActivity.class);
startActivity(openStartingPoint);

使用操作名称​​也应该,只要它与AndroidManifest.xml中的名称匹配:

Intent openStartingPoint = new Intent("com.mwmnj.criticmatch.CRITICMATCHACTIVITY");

答案 1 :(得分:0)

我的猜测是你在Eclipse资源管理器中选择了错误的项目。

如果要为laucher选择其源文件,那么该项目或其中一个应用程序。即使您当前正在编辑此项目的来源。