使用android应用程序。这个

使用android应用程序。这个,android,Android,我在主页上找不到原因。上面写着:com.exampel.pizzera不是封闭类,我换了电脑会影响吗 致意 阿曼多问题在于以下几行 package com.example.arel0002.pizzeria; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; /

我在主页上找不到原因。上面写着:
com.exampel.pizzera
不是封闭类,我换了电脑会影响吗

致意


阿曼多

问题在于以下几行

package com.example.arel0002.pizzeria;

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

/**
 * Created by arel0002 on 2015-06-01.
 */
public class pizza extends Activity {
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mainpage);
        View button = (View) findViewById(R.id.pizza);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(mainpage.this, pizza.class);
                startActivity(i);
            }
        }
    }
}
您的类被称为
pizza
而不是
mainpage
。第一个参数应该是
pizza.this
,而不是
mainpage.this
。第二个参数是要启动的活动。在您的情况下,您正在启动一个新的
比萨饼实例。Aso你错过了
setOnClickListener
中选择code>。应该是

 Intent i = new Intent(mainpage.this, pizza.class);

您没有使用正确的意图构造函数参数。 文档中的定义如下所示-

setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(mainpage.this, pizza.class);
                startActivity(i);
            }
 });
/**
*为特定组件创建意图。所有其他字段(操作、数据、,
*类型、类)为空,但稍后可以使用显式
*电话。这提供了一种方便的方法来创建
*用于执行硬编码的类名,而不是依赖
*系统为您找到合适的班级;见{@link#setComponent}
*更多关于这一事件影响的信息。
*
*@param packageContext实现的应用程序包的上下文
*这个班。
*@param cls用于意图的组件类。
*
*@see#setClass
*@see#setComponent
*@see#Intent(字符串,android.net.Uri,上下文,类)
*/
公共意图(上下文包上下文,类cls){
mComponent=新组件名称(packageContext,cls);
}
您的意图实例可以是这样的-

/**
     * Create an intent for a specific component.  All other fields (action, data,
     * type, class) are null, though they can be modified later with explicit
     * calls.  This provides a convenient way to create an intent that is
     * intended to execute a hard-coded class name, rather than relying on the
     * system to find an appropriate class for you; see {@link #setComponent}
     * for more information on the repercussions of this.
     *
     * @param packageContext A Context of the application package implementing
     * this class.
     * @param cls The component class that is to be used for the intent.
     *
     * @see #setClass
     * @see #setComponent
     * @see #Intent(String, android.net.Uri , Context, Class)
     */
    public Intent(Context packageContext, Class<?> cls) {
        mComponent = new ComponentName(packageContext, cls);
    }
Intent Intent=newintent(pizza.this,)

问题现在变成了}}它说)和;应为(中间的2})
Intent intent = new Intent(pizza.this,<TargetingActivity.class>)