Java 打开活动错误

Java 打开活动错误,java,android,layout,android-activity,Java,Android,Layout,Android Activity,hi-ppl(我是android的noob) 我创建了一个应用程序,但该应用程序无法打开一个新活动来打开更多布局,可以帮助我吗 我的代码是: 布局 main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"

hi-ppl(我是android的noob) 我创建了一个应用程序,但该应用程序无法打开一个新活动来打开更多布局,可以帮助我吗

我的代码是:

布局 main.xml:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#f9f9f9"
>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    >
        <LinearLayout

            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
        >
            <Button
                style="@style/Button"
                android:text="@string/wireless"
                android:onClick="OpenWireless"
            />
            <Button
                style="@style/Button"
                android:text="Button 1"
            />
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="TextView"
            />
        </LinearLayout>
    </ScrollView>
</LinearLayout>
无线活动:

    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pacl.hackdroid;

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

/**
 *
 * @author simao.lemos
 */
public class WirelessActivity extends Activity {

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.wireless);
        // ToDo add your GUI initialization code here
    }

}

我的错误是什么?

你忘了调用
startActivity

    Intent Wireless;
    Wireless = new Intent(this, WirelessActivity.class);
    startActivity(Wireless);

Intent提供了一种工具,用于在不同应用程序中的代码之间执行后期运行时绑定。它最重要的用途是在启动活动时,可以将其视为活动之间的粘合剂。它基本上是一个被动数据结构,包含对要执行的操作的抽象描述

public class MainActivity extends Activity
{
    /** Called when the activity is first created.
     * @param savedInstanceState */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      OpenWireless();
    }
    public void OpenWireless()
    {
        TextView textView;
        textView = (TextView) findViewById(R.id.textView);
        textView.setText("123");

        Intent w;
        w = new Intent(this, WirelessActivity.class);
        startActivity(w);
    }

}        

用这种方法改变你的想法

public void OpenWireless(View view)
        {
            TextView textView;
            textView = (TextView) findViewById(R.id.textView);
            textView.setText("123");

            Intent Wireless;
            Wireless = new Intent(this, WirelessActivity.class);
            startActivity(Wireless);

        }

这将打开下一个活动。

在此处添加startActivity

Intent wirelessIntent = new Intent(this, WirelessActivity.class);
startActivity(wirelessIntent);
还可以在应用程序标记之间提到清单文件中的活动,如下所示

<activity android:name=".WirelessActivity"
        />

否则,应用程序将显示您在点击按钮后强制关闭

Intent wirelessIntent = new Intent(this, WirelessActivity.class);
startActivity(wirelessIntent);
<activity android:name=".WirelessActivity"
        />