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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:28:44+00:00 2026-06-09T14:28:44+00:00

I am a newbie to Android development. I have two Java files in my

  • 0

I am a newbie to Android development. I have two Java files in my project. One file contains my main activity so I want to transfer the data from one Java file to another which contains the main activity.

cordovaExample.java:

package org.apache.cordova.example;

import android.content.Context;
import android.content.Intent;
import android.telephony.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import org.apache.cordova.*;
public class cordovaExample extends DroidGap
{
@Override
 public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");

    Bundle extras = getIntent().getExtras();
    String phno = extras.getString("novel.PhoneNumber");
   Toast.makeText(getApplicationContext(),phno,Toast.LENGTH_LONG).show();



}
}

novel.java

package org.apache.cordova.example;

import android.content.Context;
import android.content.Intent;
import android.telephony.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class novel extends Activity
{ 
public String PhoneNumber;
Context mcontext;
public String getNumber()
{



 TelephonyManager tMgr=(TelephonyManager)mcontext.getSystemService(Context.TELEPHONY_SERVICE); 

         Intent intent = new Intent(this, cordovaExample.class);
            intent.putExtra("novel.PhoneNumber", PhoneNumber);
                startActivity(intent);
               return PhoneNumber = tMgr.getLine1Number();
        }

}

So i want to transfer the "PhoneNumber" from novel.java to cordovaExample.java but in novel.java, After running the application i am getting "unfortunately app has stopped" in emulator.

this is the logcat

08-12 15:49:37.657: E/AndroidRuntime(779): FATAL EXCEPTION: main
08-12 15:49:37.657: E/AndroidRuntime(779): java.lang.RuntimeException: Unable to start activity  ComponentInfo{org.apache.cordova.example/org.apache.cordova.example.cordovaExample}: java.lang.NullPointerException
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.os.Looper.loop(Looper.java:137)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-12 15:49:37.657: E/AndroidRuntime(779):  at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:49:37.657: E/AndroidRuntime(779):  at java.lang.reflect.Method.invoke(Method.java:511)
08-12 15:49:37.657: E/AndroidRuntime(779):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-12 15:49:37.657: E/AndroidRuntime(779):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-12 15:49:37.657: E/AndroidRuntime(779):  at dalvik.system.NativeStart.main(Native Method)
08-12 15:49:37.657: E/AndroidRuntime(779): Caused by: java.lang.NullPointerException
08-12 15:49:37.657: E/AndroidRuntime(779):  at org.apache.cordova.example.cordovaExample.onCreate(cordovaExample.java:20)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.Activity.performCreate(Activity.java:4465)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-12 15:49:37.657: E/AndroidRuntime(779):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-12 15:49:37.657: E/AndroidRuntime(779):  ... 11 more

Also, if I try the simple program I get the same result:

cordovaExample.java

package org.apache.cordova.example;

import android.content.Context;
import android.content.Intent;
import android.telephony.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import org.apache.cordova.*;
public class cordovaExample extends DroidGap
{
@Override
 public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.loadUrl("file:///android_asset/www/index.html");

   novel c=new novel()
   int a=c.getNumber();
   Toast.makeText(getApplicationContext(),a,Toast.LENGTH_LONG).show();



}
}

novel.java

package org.apache.cordova.example;

import android.content.Context;
import android.content.Intent;
import android.telephony.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class novel extends Activity
{ 
public int a=0;
public int getNumber()
{

    a=5;

 return a;
        }

}

How can I resolve this?

  • 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-09T14:28:46+00:00Added an answer on June 9, 2026 at 2:28 pm

    Android API guide contains a definitive FAQ item about how to pass data between between Activities/Services within a single application.

    try this,

    do like this in novel to set the phone number

    Intent myIntent = new Intent(novel.this, cordovaExample.class);
    myIntent.putExtra("phone", 989898989);
    startActivity(myIntent);
    

    in cordovaExample file do following to get the phoneNumber

    Bundle b = this.getIntent().getExtras();
    String i = b.getString("phone");
    

    if you are not able to pass the data then alternative way is to declare public method and pass them, see following example,

    novel.java

    private static String phoneNumber = "";
    
    public void onCreate()
    {
        ...
        phoneNumber = "9898989898";
        ...
    }
    
    public static String getPhoneNumber()
    {
          return phoneNumber;
    }
    

    cordovaExample.java

    private static String phoneNumber = ""; 
    
    phoneNumber = novel.getPhoneNumber();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am newbie for Android Development. i don't have any idea for creating Scientific
I'm a newbie in Android Development and I want to implement Spinner . My
I am newbie in android, in my android app, a main Activity class, which
Everyone, I am a newbie to android development. Now I have a question that
Hi am newbie to android development. I had created one application where i need
I am a newbie to android app development. I want to customize my android
I'm a newbie in Android development. Let me explain my problem. I've have a
I am a newbie to Android app development. For 1 of my project, I
I am a newbie to Android programming. I want two radio buttons that when
I am newbie in Android development. Want to know about something related to my

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.