Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:03:53+00:00 2026-06-09T05:03:53+00:00

I am programming a twitter app. I am making a search bar for usernames/hashtags,

  • 0

I am programming a twitter app. I am making a search bar for usernames/hashtags, and I am having some trouble adding views generated from XML to the currently existing LinearLayout.

here is Search.java

public class Search extends Activity{

String searchType = "username";

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search);

    EditText t = (EditText)findViewById(R.id.search_content);
    t.setOnClickListener(onClickSearch);
    t.setWidth(225);

    Button b = (Button)findViewById(R.id.search_button_search);
    b.setOnClickListener(onClickButton);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_search, menu);
    return true;
}

OnClickListener onClickSearch = new OnClickListener(){

    public void onClick(View v) {
        EditText searchContent = (EditText)findViewById(R.id.search_content);
        EditText clickedContent = (EditText)v;
        if((EditText)findViewById(R.id.search_content) == (EditText)v){
            EditText t = (EditText)v;
            t.setText("");
        }

        //EditText searchContent = (EditText)findViewById(R.id.search_content);
        //EditText clickedContent = (EditText)v;

        /*if((Button)v == (Button)findViewById(R.id.search_button_type)){
            EditText t = (EditText)findViewById(R.id.search_content);
            Search.this.searchByUserName(t.getText().toString());
        }

        if((Button)v == (Button)findViewById(R.id.search_button_search)){

        }*/
    }

};

OnClickListener onClickButton = new OnClickListener(){

    public void onClick(View v) {
        //if((Button)v == (Button)findViewById(R.id.search_button_search)){
            EditText t = (EditText)findViewById(R.id.search_content);
            Search s = new Search();
            s.searchByUserName(t.getText().toString());
        //}

        //if((Button)v == (Button)findViewById(R.id.search_button_search)){

        //}
    }

};

public void searchByUserName(String userName){
    //System.out.println("beginning->searchByUserName");
    TwitterHandler handler = new TwitterHandler();
    List<View> views = handler.queryUserName(userName, this);

    LinearLayout ll = (LinearLayout)findViewById(R.id.search_panel);
    for(int i = 0; i < views.size(); i++){
        ll.addView(views.get(i));
    }
}

}

here is the XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/search_panel" >
    <Button
       android:id="@+id/search_button_type"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Search Type"/>

    <EditText
        android:id="@+id/search_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Search Here" >
    </EditText>

    <Button
        android:id="@+id/search_button_search"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Search"/>
</LinearLayout>

My LogCat is telling me there is a NullPointerException, the process is forced to quit on the android virtual device. Please Help!!!

Here is the TwitterHandler

public class TwitterHandler extends DefaultHandler{
private final String USER_SEARCH = "https://api.twitter.com/1/users/lookup.xml?screen_name=";

public List<View> queryUserName(String userName, Context context){
    System.out.println("beginning->queryUserName");
    String url = USER_SEARCH + userName;
    //ListView view = new ListView(context);
    List<View> views = new ArrayList<View>();
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        System.out.println("in try statement->queryUserName");
        DocumentBuilder db = dbf.newDocumentBuilder();

        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(url));
        doc = db.parse(is); 

        NodeList nl = doc.getChildNodes();

        for(int i = 0; i < nl.getLength(); i++){
            Element e = (Element)nl.item(i);
            TextView t = new TextView(context);

            String name = "";
            String screenName = "";
            Bitmap bitmap = null;

            Node n = (Node)e.getChild("name");
            name = n.getTextContent();
            t.setText(name);
            views.add(t);

            t = new TextView(context);
            n = (Node)e.getChild("screen_name");
            screenName = n.getTextContent();
            t.setText(screenName);
            views.add(t);

            n = (Node)e.getChild("profile_image_url");
            bitmap = getBitmap(n.getTextContent());
            ImageView imageView = new ImageView(context);
            imageView.setImageBitmap(bitmap);
            views.add(imageView);

        }

    }catch(Exception e){ }
    return views;
}

private Bitmap getBitmap(String imageUrl) throws IOException{
InputStream inputStream = null;
 URL u = new URL(imageUrl);
 URLConnection conn = u.openConnection();

 try{
      HttpURLConnection httpConn = (HttpURLConnection)conn;
      httpConn.setRequestMethod("GET");
      httpConn.connect();

      if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
          inputStream = httpConn.getInputStream();
      }
 }
 catch (Exception ex) { }

return BitmapFactory.decodeStream(inputStream);

}

}

Here is the Log

07-26 17:00:24.523: D/AndroidRuntime(335): Shutting down VM
07-26 17:00:24.523: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception     (group=0x40015560)
07-26 17:00:24.533: E/AndroidRuntime(335): FATAL EXCEPTION: main
07-26 17:00:24.533: E/AndroidRuntime(335): java.lang.ClassCastException:   java.util.AbstractList$SubAbstractListRandomAccess
07-26 17:00:24.533: E/AndroidRuntime(335):  at    com.example.twitter.viewer.Search.searchByUserName(Search.java:84)
07-26 17:00:24.533: E/AndroidRuntime(335):  at com.example.twitter.viewer.Search$2.onClick(Search.java:71)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.view.View.performClick(View.java:2485)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.view.View$PerformClick.run(View.java:9080)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.os.Handler.handleCallback(Handler.java:587)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.os.Looper.loop(Looper.java:123)
07-26 17:00:24.533: E/AndroidRuntime(335):  at android.app.ActivityThread.main(ActivityThread.java:3683)
07-26 17:00:24.533: E/AndroidRuntime(335):  at java.lang.reflect.Method.invokeNative(Native Method)
07-26 17:00:24.533: E/AndroidRuntime(335):  at java.lang.reflect.Method.invoke(Method.java:507)
07-26 17:00:24.533: E/AndroidRuntime(335):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-26 17:00:24.533: E/AndroidRuntime(335):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-26 17:00:24.533: E/AndroidRuntime(335):  at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:03:55+00:00Added an answer on June 9, 2026 at 5:03 am

    You are trying to make a new Instance Object of your Search Activity.
    In which your contentView is not available, so you can not define LinearLayout at searchByUserName method.

    Instead just simple use method name..

    So Replace these lines,

    Search s = new Search();
    s.searchByUserName(t.getText().toString());
    

    with only,

    searchByUserName(t.getText().toString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get up to speed on programming Twitter but am having trouble
My programming background comes from C and some C++ programming with strong emphasis on
Im new to python programming.Im writing a simple command line based twitter app,and i
I was having a discussion on twitter about adding the ability of Ruby to
Programming for my Arduino (in some kind of mix of C/C++), I noticed something
Android programming. I have a json returning the date from a database as a
I'm working through the Stanford iPhone programming course online. The Presence app assignment pulls
I'm programming a little Twitter Client just for fun. I have the tweet's text
I am new to web programming, coming from a video game development background (c++),
Programming Language I am using : PHP I have 30 results from database, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.