我正在尝试启动一个新活动的搜索按钮的OnClick


这个代码在几周前就可以正常工作了,突然之间
错误。
我该如何清除




AndroidTabRestaurantDescListView.java

public class AndroidTabRestaurantDescListView extends TabActivity {

    // TabSpec Names
    private static final String INBOX_SPEC = "Rating";
    private static final String OUTBOX_SPEC = "Price";
    private static final String PROFILE_SPEC = "Distance";

    Button Photos;
    Button Filter;
    Button Search;
    Button Account;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Photos=(Button) findViewById(R.id.PhotoButton);
        Filter=(Button) findViewById(R.id.FilterButton);
        Search=(Button) findViewById(R.id.SearchBottomBarID);
        Account=(Button) findViewById(R.id.AccountBottomBarID);

        TabHost tabHost = getTabHost();

        // Inbox Tab
        TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
        Intent inboxIntent = new Intent(this, MainActivity.class);
        inboxSpec.setIndicator(INBOX_SPEC);
        // Tab Content
        inboxSpec.setContent(inboxIntent);

        // Outbox Tab
        TabSpec PriceSpec = tabHost.newTabSpec(OUTBOX_SPEC);
        Intent PriceIntent = new Intent(this, PriceDescriptionActivity.class);
        PriceSpec .setIndicator(OUTBOX_SPEC);
        PriceSpec.setContent(PriceIntent);

        // Profile Tab
        TabSpec DistanceSpec = tabHost.newTabSpec(PROFILE_SPEC);
        Intent DistanceIntent = new Intent(this, DistanceDiscriptionActivity.class);
        DistanceSpec .setIndicator(PROFILE_SPEC);
        DistanceSpec.setContent(DistanceIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(inboxSpec);
        tabHost.addTab(PriceSpec);
        tabHost.addTab(DistanceSpec);

        //Set the current value tab to default first tab
        tabHost.setCurrentTab(0);

        //Setting custom height for the tabs
        final int height = 45;
        tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
        tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
        tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;




        Photos.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent PhotoIntent=new Intent(AndroidTabRestaurantDescListView.this,AndroidTabRestaurantDescImageListView.class);
                startActivity(PhotoIntent);

            }
        });


        Filter.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent FilterIntent=new Intent(AndroidTabRestaurantDescListView.this,Filters.class);
                startActivity(FilterIntent);
            }
        });


        Search.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent FilterIntent=new Intent(AndroidTabRestaurantDescListView.this,SearchPage.class);
                startActivity(FilterIntent);
            }
        });


        Account.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent PhotoIntent=new Intent(AndroidTabRestaurantDescListView.this,RestaurantAccount.class);
                startActivity(PhotoIntent);

            }
        });


    }

}


SearchPage.java

public class SearchPage extends FragmentActivity {

    EditText mEdit;
    EditText City;
    Button Back;
    Button Search;


    private RadioGroup rdg;
    private RadioButton breakFast;
    private RadioButton lunch;
    private RadioButton dinner;


    private String selectedType="";



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_page);

        City=(EditText) findViewById(R.id.CITY_ID);


        rdg = (RadioGroup) findViewById(R.id.radioGroup1);
        breakFast = (RadioButton) findViewById(R.id.BreakfastRG_ID);
        lunch = (RadioButton) findViewById(R.id.LunchRG_ID);
        dinner = (RadioButton) findViewById(R.id.DinnerRG_ID);
        breakFast.setSelected(true);

        rdg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.BreakfastRG_ID){
                    selectedType = breakFast.getText().toString();
                }else if(i==R.id.LunchRG_ID){
                    selectedType = lunch.getText().toString();
                }else{
                    selectedType = dinner.getText().toString();
                }
            }
        });

        Back=(Button) findViewById(R.id.TopNavigationBarRestaurantSearchActivityBackButton);
        Back.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                 finish();
            }
        });

        Search=(Button) findViewById(R.id.SEARCH_BUTTON_ID);
        Search.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent searchIntent=new Intent(SearchPage.this,AndroidTabRestaurantDescSearchListView.class);
                searchIntent.putExtra("REST",City.getText().toString());
                searchIntent.putExtra("REST1",selectedType);
                Log.i ("REST-IN-SEARCHPAGE", City.toString ());
                Log.i ("TYPE-IN-SEARCHPAGE", selectedType.toString ());
                startActivity(searchIntent);
            }
        });


    }

    public void selectDate(View view) {
        DialogFragment newFragment = new SelectDateFragment();
        newFragment.show(getSupportFragmentManager(), "DatePicker");
    }
    public void populateSetDate(int year, int month, int day) {
        mEdit = (EditText)findViewById(R.id.DATE_EDIT_TEXT_ID);
        mEdit.setText(day+"/"+month+"/"+year);
    }
    public class SelectDateFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Calendar calendar = Calendar.getInstance();
            int yy = calendar.get(Calendar.YEAR);
            int mm = calendar.get(Calendar.MONTH);
            int dd = calendar.get(Calendar.DAY_OF_MONTH);
            return new DatePickerDialog(getActivity(), this, yy, mm, dd);
        }

        public void onDateSet(DatePicker view, int yy, int mm, int dd) {
            populateSetDate(yy, dd, mm+1);
        }
    }
}


日志::

12-26 11:43:06.243: E/AndroidRuntime(506): Uncaught handler: thread main exiting due to uncaught exception
12-26 11:43:06.253: E/AndroidRuntime(506): java.lang.NoClassDefFoundError: com.project.findmybuffet.SearchPage
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.project.findmybuffet.AndroidTabRestaurantDescListView$3.onClick(AndroidTabRestaurantDescListView.java:101)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.View.performClick(View.java:2364)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.View.onTouchEvent(View.java:4179)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.View.dispatchTouchEvent(View.java:3709)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.os.Looper.loop(Looper.java:123)
12-26 11:43:06.253: E/AndroidRuntime(506):  at android.app.ActivityThread.main(ActivityThread.java:4363)
12-26 11:43:06.253: E/AndroidRuntime(506):  at java.lang.reflect.Method.invokeNative(Native Method)
12-26 11:43:06.253: E/AndroidRuntime(506):  at java.lang.reflect.Method.invoke(Method.java:521)
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12-26 11:43:06.253: E/AndroidRuntime(506):  at dalvik.system.NativeStart.main(Native Method)




注意:我已经在清单中声明了这两项活动

最佳答案

12-26 11:43:06.253: E/AndroidRuntime(506): java.lang.NoClassDefFoundError: com.project.findmybuffet.SearchPage
12-26 11:43:06.253: E/AndroidRuntime(506):  at com.project.findmybuffet.AndroidTabRestaurantDescListView$3.onClick(AndroidTabRestaurantDescListView.java:101)


无法找到com.project.findmybuffet.SearchPage类。请检查一次您的包裹名称。

<activity android:name="com.project.findmybuffet.SearchPage" >
        </activity>


您在此路径"com.project.findmybuffet.SearchPage"中提到了搜索页活动,因此请检查SearchPage.class是否在该路径中。
 如果一切都很好。尝试清理您的项目,然后再次运行

现在试试这个

Photos.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent photoIntent=new Intent(AndroidTabRestaurantDescListView.this,AndroidTabRestaurantDescImageListView.class);
                startActivity(photoIntent);

            }
        });


        Filter.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent filterIntent=new Intent(AndroidTabRestaurantDescListView.this,Filters.class);
                startActivity(filterIntent);
            }
        });


        Search.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent searchIntent=new Intent(AndroidTabRestaurantDescListView.this,SearchPage.class);
                startActivity(searchIntent);
            }
        });


        Account.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent accountIntent=new Intent(AndroidTabRestaurantDescListView.this,RestaurantAccount.class);
                startActivity(accountIntent);

            }
        });

09-26 23:38