-1

I am creating an application consists of search widget on action bar which was downloaded from here and i had placed in a my layout.xml but it was showing error on the xml called

The following classes could not be instantiated:The following classes could not be instantiated: - com.milan.searchmenu.persistentsearch.SearchBox (Open Class, Show Error Log) See the Error Log (Window > Show View) for more details. Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse java.lang.NullPointerException By running application also run time null pointer exception occurs can any one tell me how to fix this: This is my activity:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.manual);
        ActionBar actionbar;
        actionbar = getActionBar();
        search = (SearchBox) findViewById(R.id.searchbox);
        search.enableVoiceRecognition(this);
        for(int x = 0; x < 10; x++){
            com.milan.searchmenu.persistentsearch.SearchResult option = new SearchResult("Result " + Integer.toString(x), getResources().getDrawable(R.drawable.ic_history));
            search.addSearchable(option);
        }       
        search.setMenuListener(new MenuListener(){

            @Override
            public void onMenuClick() {
                //Hamburger has been clicked
                Toast.makeText(Manual.this, "Menu click", Toast.LENGTH_LONG).show();                
            }

        });

        search.setSearchListener(new SearchListener() {

            @Override
            public void onSearchTermChanged() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSearchOpened() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSearchClosed() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSearchCleared() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSearch(String result) {
                Toast.makeText(Manual.this, result +" Searched", Toast.LENGTH_LONG).show();

            }
        });

This is my XML:

<RelativeLayout
        android:id="@+id/Relative_layout"
        android:layout_width="wrap_content"
        android:layout_height="51dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true" 
        android:background="#673AB7">

        <com.milan.searchmenu.persistentsearch.SearchBox
        android:layout_width="wrap_content"
        android:id="@+id/searchbox"
        android:layout_height="wrap_content">
        </com.milan.searchmenu.persistentsearch.SearchBox>
    </RelativeLayout>


   <android.support.v4.view.ViewPager
       android:id="@+id/pager"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_below="@+id/pager_sliding_tab_strip">

   </android.support.v4.view.ViewPager>

   <com.milan.tabs.pagerslidingstrip.PagerSlidingTabStrip
       android:id="@+id/pager_sliding_tab_strip"
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:layout_alignParentLeft="true"
       android:layout_below="@+id/Relative_layout"
       android:textSize="15dp"
       app:pstsShouldExpand="true"
       app:pstsDividerColor="#B39DDB"
       app:pstsIndicatorHeight="45dp" 
       android:background="#673AB7"
       app:pstsIndicatorColor="#FFFFFF">



   </com.milan.tabs.pagerslidingstrip.PagerSlidingTabStrip>



    }
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
BujjiDeepu
  • 111
  • 1
  • 14

2 Answers2

0

You need to add the downloaded library as a dependency of your module. In Android Studio do the following

  1. Place the library in your project somewhere.
  2. Right click on the library and select "Add as Library"
  3. Choose your main module: usually either called app or mobile.
  4. Rebuild and it should work
StuStirling
  • 15,601
  • 23
  • 93
  • 150
  • I am doing in eclipse dude@Disco S2 – BujjiDeepu Jul 02 '15 at 08:30
  • 1
    Ah sorry. I honestly can't remember how to do it in Eclipse. It's been too long :) thought about moving to Android Studio? It's awesome – StuStirling Jul 02 '15 at 08:31
  • Thanks for answer dude but my project is at peak stage at this time i don't want to take risk to migrate to android studio at this time next time i'll do it defiantly – BujjiDeepu Jul 02 '15 at 08:36
0

From the post what I understood is that you are having this issue while developing the app and not running.

If the issue is that the layout file is not loading in design view, it will be an issue with the SearchBox control you used in layout.

com.milan.searchmenu.persistentsearch.SearchBox

In custom views, while rendering in design view, it cannot work fully. For example if the custom view is accessing something from assets etc, that dependency will be resolved at runtime only and not in design mode, Because of which you got this error.

So for fixing you need to put those kind of codes inside the if block of View.isInEditMode().

Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
  • Where i can find the view.isInEdit mode dude@Eldhose M Babu – BujjiDeepu Jul 02 '15 at 08:51
  • @BujjiDeepu Its a static function of View. You need to use that function while creating Custom views inside the onDraw method. This function is used to distinguish between whether the view is loaded in Design mode or Actual run of application. In this case, if you are not having the code of custom view, you cannot do anything. – Eldhose M Babu Jul 02 '15 at 08:58