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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:13:23+00:00 2026-05-27T15:13:23+00:00

Hi everyone this is my first Android app. I new to Java and Eclipse

  • 0

Hi everyone this is my first Android app. I new to Java and Eclipse so excuse any “noobity”.
I created this project and the tried to run it on my device (nexus s). This is what i get in the LogCat.

12-17 21:03:11.550: E/AndroidRuntime(20786): FATAL EXCEPTION: main  
12-17 21:03:11.550: E/AndroidRuntime(20786): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gsmdata/com.example.gsmdata.GsmDataActivity}: java.lang.NullPointerException  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread.access$1500  (ActivityThread.java:117)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.os.Handler.dispatchMessage(Handler.java:99)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.os.Looper.loop(Looper.java:130)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread.main(ActivityThread.java:3683)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at java.lang.reflect.Method.invokeNative(Native Method)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at java.lang.reflect.Method.invoke(Method.java:507)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at dalvik.system.NativeStart.main(Native Method)  
12-17 21:03:11.550: E/AndroidRuntime(20786): Caused by: java.lang.NullPointerException  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at com.example.gsmdata.GsmDataActivity.onCreate(GsmDataActivity.java:72)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)  
12-17 21:03:11.550: E/AndroidRuntime(20786):    ... 11 more

public class GsmDataActivity extends Activity {
/** Called when the activity is first created. */ 

int[] SignalStrength = {
        -113,
        -111,
        -109,
        -107,
        -105,
        -103,
        -101,
        -99,
        -97,
        -95,
        -93,
        -91,
        -89,
        -87,
        -85,
        -83,
        -81,
        -79,
        -77,
        -75,
        -73,
        -71,
        -69,
        -67,
        -65,
        -63,
        -61,
        -59,
        -57,
        -55,
        -53,
        -51};

int network_type,signal_strength,cid,Lac,bts;
TextView network, signal, ci, lac;
TelephonyManager phone;
GsmCellLocation cellId;
CdmaCellLocation baseStation;
SignalStrength phone_sig;

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

    network = (TextView) findViewById(R.id.tvNetwork);
    signal =(TextView) findViewById(R.id.tvSignalValue);
    ci = (TextView) findViewById(R.id.tvCiValue);
    lac = (TextView) findViewById(R.id.tvLacValue);

    network_type=phone.getNetworkType();

    switch (network_type){ 

    case 1: network.setText("GPRS");
    case 3: network.setText("UMTS");
    case 4: network.setText("CDMA");
    case 8: network.setText("HSDPA");
    case 9: network.setText("HSUPA");
    case 10: network.setText("HSPA");
    case 13: network.setText("LTE");
    default: network.setText("UNKNOWN");      

    }

    if (network_type==1){
        signal_strength = phone_sig.getGsmSignalStrength();
        signal.setText(SignalStrength[signal_strength] + "dBm");
        cid= cellId.getCid();
        Lac=cellId.getLac();
    }
    else if(network_type==0){
        signal.setText("Unknown Network type");
    }
    else{
        signal_strength= phone_sig.getCdmaDbm();
        signal.setText(SignalStrength[signal_strength] + "dBm");
        bts= baseStation.getBaseStationId(); 
        Lac=cellId.getLac();
    }


}



}

This is my java class. I get a FATAL EXCEPTION in main. I dont know why. Can you help me. Thank you in advance. Following is the xml code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

 <TextView 
android:layout_width= "fill_parent"
android:layout_height="wrap_content"
android:textSize="50dp"
android:paddingBottom="5dp"
android:id="@+id/tvNetwork"
></TextView>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
 android:text="@string/strength"
 android:layout_gravity="center"
    android:paddingBottom="5dp"
 android:id="@+id/tvSignal"
/>
<TextView 
android:layout_width= "fill_parent"
android:layout_height="wrap_content" 
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvSignalValue"
></TextView>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:text="@string/cellid"
 android:layout_gravity="center"
 android:paddingBottom="5dp"
 android:id="@+id/tvCi"
/>
 <TextView 
android:layout_width= "fill_parent"
android:layout_height="wrap_content" 
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvCiValue"
></TextView>   
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
 android:text="@string/lac"
 android:layout_gravity="center"
 android:id="@+id/tvLac"
/>
<TextView 
android:layout_width= "fill_parent"
android:layout_height="wrap_content" 
android:textSize="50dp"
android:paddingBottom="5dp"
android:gravity="center"
android:id="@+id/tvLacValue"
></TextView>    
</LinearLayout>
  • 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-27T15:13:23+00:00Added an answer on May 27, 2026 at 3:13 pm

    phone is null when you call phone.getNetworkType();, therefore you get NullPointerException.

    Assign the telephonty manager to it first:

    phone = getSystemService(Context.TELEPHONY_SERVICE);
    phone.getNetworkType();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just want to let everyone know this is the first app I am trying
hii everyone am sowmya am brand new to android please can any one help
Hey everyone.. This is my first time writing an ASP.NET MVC web app, and
everyone. I'm new here and this is my first post. I'm creating a simple
This is my first question. Thanks to everyone who contributes to this site, it's
First, I would to thank everyone for all the help they provide via this
thank you everyone for helping me out with this. i am new to ruby
This is not a new topic, but I am curious how everyone is handling
First off, thank you to everyone on this site...it's been INCREDIBLY helpful in getting
Hi everyone this is my first question here and im not a programmer. I

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.