2

我知道有很多关于此的问题,但我无法弄清楚为什么我的程序一直加载错误的活动,即使我已将正确的活动设为清单中的默认值。这是给大家的一些代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="swin.examples"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="swin.examples.TemperatureConvertor"
                  android:label="@string/app_name">
        </activity>        
        <activity android:name="swin.examples.FeetToCmConvertor"
                  android:label="@string/app_name">
        </activity>
        <activity android:name="swin.examples.Main" 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>
</manifest> 

这就是我认为如果清单中没有问题的地方:

package swin.examples;

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

public class Main extends Activity 
{

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

private void initializeUI()
{
    Button btnCm = (Button)findViewById(R.id.btnFeet);
    btnCm.setOnClickListener(btnFeetListener);
    Button convertButton = (Button)findViewById(R.id.btnTemp);
    convertButton.setOnClickListener(btnTempListener);

}

/** Handle convert button click */ 
private OnClickListener btnTempListener = new OnClickListener() 
{
    public void onClick(View v) 
    {
            convertButtonClicked();
    }
};

private OnClickListener btnFeetListener = new OnClickListener() 
{
    public void onClick(View v) 
    {
            btnCmClicked();
    }
};

private void btnCmClicked()
{
    // set the sender and the receiver of the intent
    Intent intent = new Intent();
    intent.setClass(getApplicationContext(), swin.examples.FeetToCmConvertor.class);

    startActivity(intent); // transmit your intent

}

private void convertButtonClicked()
{
    // set the sender and the receiver of the intent
    Intent intent = new Intent();
    intent.setClass(getApplicationContext(), swin.examples.TemperatureConvertor.class);

    startActivity(intent); // transmit your intent  
}
}

我无法解决,我希望你能帮助我!非常感谢您!

编辑:代码已更新,但仍然无法正常工作。如果这有帮助,这是日志消息:

[2013-04-20 22:44:20 - CombinedConvertor] Success!
[2013-04-20 22:44:21 - CombinedConvertor] Starting activity swin.examples.TemperatureConvertor on device emulator-5554
[2013-04-20 22:44:23 - CombinedConvertor] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=swin.examples/.TemperatureConvertor }
4

2 回答 2

3

适合IntentFilter主要Activity的是

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
于 2013-04-20T12:31:43.757 回答
0

有史以来最奇怪的错误。为其他人工作,而不是我。重新制作温度转换器活动,它现在可以工作了。谢谢你们每一个人的帮助!

于 2013-04-21T04:19:39.770 回答