简体   繁体   中英

launching a new activity on click of button

OnClick of search button i am trying to launch a new activity

  • well this code was working few weeks ago, all of sudden giving errors.
  • How can i clear this

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);
        }
    }
}

log ::

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)

note :: I have declared both activities in manifest


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)

It is unable to find com.project.findmybuffet.SearchPage class. Please check your package name once.

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

You have mentioned your search page activity in this path "com.project.findmybuffet.SearchPage" so please check whether that SearchPage.class is in that path or not. If everything is good. Try clean your project and run again

Now try this

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);

            }
        });

I Used this link to resolve the solution & ansewr of saa also helped

i just selected all the options in the screenshot below

在此输入图像描述在此输入图像描述

The error you are getting acoording to the log is a problem concerning ClassPaths.

Read here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM