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 6374559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:30:11+00:00 2026-05-25T01:30:11+00:00

My android app won’t seem to start. I made a few code changes in

  • 0

My android app won’t seem to start. I made a few code changes in the main activity, tried to launch it and it crashed on launch. I then removed those code changes and it still won’t launch. I can’t find anything wrong with the code, here is the main activity:

public class MainActivity extends TabActivity implements OnClickListener {


Button doSomething;
TabHost tabHost;
ViewFlipper flipper;
ListView listview;
ListView listview2;
HttpResponse re;
String json;
JSONObject j;
ListAdapter adapter2;



/*==================*/

ListView lazyList;
LazyAdapter lazyAdapter;
/*==================*/


private static final String LOG_TAG = "App";



@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void onCreate(Bundle savedInstanceState) {




    super.onCreate(savedInstanceState);




    doSomething = (Button) findViewById(R.id.btn_do_something);
    doSomething.setOnClickListener(this);

    flipper = (ViewFlipper) findViewById(R.id.layout_tab_one);

    listview = (ListView) findViewById(R.id.listview);

    listview2 = (ListView) findViewById(R.id.listview2);


    /*==================================*/

    lazyList=(ListView)findViewById(R.id.lazylistview);


   //@SuppressWarnings("unchecked")
   ListAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetch());
   adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetchList1());



   listview.setAdapter(adapter);
   listview2.setAdapter(adapter2);

    flipper.setOnClickListener(this);

    String tabname1 = getString(R.string.tabexample_tab1);
    String tabname2 = getString(R.string.tabexample_tab2);
    String tabname3 = getString(R.string.tabexample_tab3);
    String tabname4 = getString(R.string.tabexample_tab4);

    tabHost = getTabHost();
    tabHost.addTab(tabHost.newTabSpec("tab1").setContent(R.id.layout_tab_one).setIndicator(tabname1));
    tabHost.addTab(tabHost.newTabSpec("tab2").setContent(R.id.layout_tab_two).setIndicator(tabname2));
    tabHost.addTab(tabHost.newTabSpec("tab3").setContent(R.id.layout_tab_three).setIndicator(tabname3));
    tabHost.addTab(tabHost.newTabSpec("tab4").setContent(R.id.layout_tab_four).setIndicator(tabname4));

    tabHost.setCurrentTab(0);




    listview.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(AdapterView<?> a, View v, int position, long id) {



            Object item = listview.getItemAtPosition(position);






            SavePreferences("item",item.toString());
            MainActivity.this.refreshList();







             flipper.showNext();


        }});

    listview2.setOnItemClickListener(new OnItemClickListener(){
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
             flipper.showPrevious();


        }});

    lazyList.setOnItemClickListener(new OnItemClickListener(){
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
             flipper.showPrevious();


        }});








}





public ArrayList<String> fetch()
{
    ArrayList<String> listItems = new ArrayList<String>();

    try {
        URL twitter = new URL(
                "JSON.php");
        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));




        String line;
        while ((line = in.readLine()) != null) {







      //make sure youe String line is completely filled after that..
      if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
       {

      JSONArray jArray = new JSONArray(line);
      Log.v(LOG_TAG,"jarray value: " + jArray);
      for (int i = 0;i < jArray.length(); i++) 
       {

         //SONObject jobj = jArray.getJSONObject(i);
          String country = jArray.getString(i);
          listItems.add(country); 
         // also make sure you get the value from the jsonObject using some key
         // like, jobj.getString("country");


        //istItems.add(jobj.getString(""));

       }
          }

        } 

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return listItems;
}


public ArrayList<String> fetchList1()
{
    ArrayList<String> listItems = new ArrayList<String>();

    try {

        SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
        String selected = sharedPreferences.getString("item", "");



        URL twitter = new URL(
                "JSON2.php?item=" + selected);

        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));




        String line;
        while ((line = in.readLine()) != null) {







      //make sure youe String line is completely filled after that..
      if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
       {

      JSONArray jArray = new JSONArray(line);
     // Log.v(LOG_TAG,"jarray value: " + jArray);
      for (int i = 0;i < jArray.length(); i++) 
       {

         //SONObject jobj = jArray.getJSONObject(i);
          String country = jArray.getString(i);
          listItems.add(country); 
         // also make sure you get the value from the jsonObject using some key
         // like, jobj.getString("country");


        //istItems.add(jobj.getString(""));

       }
          }

        } 

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return listItems;
}


public ArrayList<String> fetchImages()
{

    ArrayList<String> listItems = new ArrayList<String>();
    try {

        SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
        String selected = sharedPreferences.getString("item", "");



        URL twitter = new URL(
                "ImageJSON.php?item="+ selected);
        Log.v(LOG_TAG,"URL**:" + twitter.toString());
        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));




        String line;
        while ((line = in.readLine()) != null) {







      //make sure youe String line is completely filled after that..
      if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
       {

      JSONArray jArray = new JSONArray(line);
     // Log.v(LOG_TAG,"jarray value: " + jArray);
      for (int i = 0;i < jArray.length(); i++) 
       {

         //SONObject jobj = jArray.getJSONObject(i);
          String country = jArray.getString(i);
          listItems.add(country); 
         // also make sure you get the value from the jsonObject using some key
         // like, jobj.getString("country");


        //istItems.add(jobj.getString(""));

       }
          }

        } 

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return listItems;
}


public ArrayList<String> fetchList2()
{

    ArrayList<String> listItems = new ArrayList<String>();
    try {

        SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
        String selected = sharedPreferences.getString("item", "");



        URL twitter = new URL(
                "JSON3.php?item="+ selected);

        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));




        String line;
        while ((line = in.readLine()) != null) {







      //make sure youe String line is completely filled after that..
      if (!line.equals(null) && !line.equals("") && line.startsWith("[")) 
       {

      JSONArray jArray = new JSONArray(line);
     // Log.v(LOG_TAG,"jarray value: " + jArray);
      for (int i = 0;i < jArray.length(); i++) 
       {

         //SONObject jobj = jArray.getJSONObject(i);
          String country = jArray.getString(i);
          listItems.add(country); 
         // also make sure you get the value from the jsonObject using some key
         // like, jobj.getString("country");


        //istItems.add(jobj.getString(""));

       }
          }

        } 

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return listItems;
}







public void refreshList() {

    /*adapter2 = null;
    adapter2 = new ArrayAdapter(this,android.R.layout.simple_list_item_1,this.fetchList1());
    listview2.setAdapter(adapter2);*/
    lazyAdapter = null;
     String[] imagesList = new String[this.fetchList1().size()];
        imagesList = this.fetchImages().toArray(imagesList);
       ArrayList<String> v = this.fetchList1(); 
       ArrayList<String> t = this.fetchList2();
        lazyAdapter=new LazyAdapter(this,imagesList,v,t);
        lazyList.setAdapter(lazyAdapter);
    //adapter2.notifyDatasetChanged();

}


   private void SavePreferences(String key, String value){
        SharedPreferences sharedPreferences = getSharedPreferences("MY_SHARED_PREF", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
       }





@Override
public void onClick(View arg0) {
    // TODO Auto-generated method stub

}

 public void onBackPressed() 
 {     
  flipper.showPrevious();

  }






}

Here’s the manifest;

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="1"
    android:versionName="1.0" package="com.myApp.android">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />
        <activity android:name=".LazyAdapter" />
        <activity android:name=".ImageLoader" />
    </application>
    <uses-sdk android:minSdkVersion="3"/>
    <uses-permission
        android:name="android.permission.INTERNET" />
</manifest> 

Log Cat Output:

08-28 11:16:32.442: ERROR/AndroidRuntime(517): FATAL EXCEPTION: main
08-28 11:16:32.442: ERROR/AndroidRuntime(517): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myApp.android/com.myApp.android.MainActivity}: java.lang.NullPointerException
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1748)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1764)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.access$1500(ActivityThread.java:122)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1002)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.os.Looper.loop(Looper.java:132)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.main(ActivityThread.java:4025)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at java.lang.reflect.Method.invokeNative(Native Method)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at java.lang.reflect.Method.invoke(Method.java:491)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at dalvik.system.NativeStart.main(Native Method)
08-28 11:16:32.442: ERROR/AndroidRuntime(517): Caused by: java.lang.NullPointerException
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at com.android.MainActivity.onCreate(MainActivity.java:84)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
08-28 11:16:32.442: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1712)
  • 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-05-25T01:30:12+00:00Added an answer on May 25, 2026 at 1:30 am

    Thats because you have a NullPointer. This line doSomething = (Button) findViewById(R.id.btn_do_something); returns null. Check if the Button id is really “btn_do_something” or if you have more than one same IDs assigned to different buttons

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android app with a ListActivity in the main view. The list
I've just added the required code to my Android app and released the update
My android app has a two word app name, and the 2nd word doesn't
I'm building an Android app and I want to copy the text value of
We have an Android app and a Web Service. We want to download part
I've got an Android app which has a periodic background Service. I want this
I'm writing an Android app where users can upload video to Youtube. I'd like
I want my Android app to take a picture, as part of something larger
I created a native Android app that basically hosts a webView control. That webView
I am writing an android app. I want to pass some data across the

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.