1

这是我的主页代码:

package com.example.splasher;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
public static String text;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    // hide statusbar of Android
    // could also be done later
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
        EditText field= (EditText) findViewById (R.id.editText1);
        field.setOnFocusChangeListener(new OnFocusChangeListener(){
            public void onFocusChange(View v, boolean hasFocus){
                if (hasFocus)    ((EditText)v).selectAll();
            }
        });
        text=field.getText().toString();
        try{
            startActivity(new Intent("com.example.splasher.View"));
            }
       catch(ActivityNotFoundException e){
       }
      }
     });
}
}

这是我调用的活动的代码:

package com.example.splasher;

import android.os.Bundle;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

public class View extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // hide statusbar of Android
        // could also be done later
    //  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    //          WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.view);
    //  TextView textview=(TextView) findViewById (R.id.textView1); 
    //  textview.setText(MainActivity.text);
        }}

这是我的清单:

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

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

    <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=".View"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.example.splasher.View" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我无法弄清楚为什么会出现此错误。有任何想法吗?名称都是相同的,并且具有相同的大写、小写字母。它们也都在清单中进行了描述。

4

4 回答 4

1

在您的清单中,以大写字母键入活动操作。

<action android:name="COM.EXAMPLE.SPLASHER.VIEW" />

这适用于除主要活动之外的所有活动

于 2013-03-16T16:59:44.820 回答
0

不需要您在 View 活动中应用的意图过滤器。只需在 MainActivity 中保留一个意图过滤器

将开始活动行代码替换为以下内容:

startActivity(new Intent(MainActivity.this,View.class));
于 2013-03-16T16:49:15.107 回答
0

尝试在 MainActivity中替换您的startActivity呼叫。MainActivity.this.startActivity我认为存在范围问题。

于 2013-03-16T17:07:06.547 回答
0

MainActivity.this.startActivity(new Intent(MainActivity.this, Views.class));'s' 的 Views 类!

于 2013-03-16T22:00:27.153 回答