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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:47:47+00:00 2026-06-18T22:47:47+00:00

I made a class and its constructor should take 2 arguments, but Eclipse gives

  • 0

I made a class and its constructor should take 2 arguments, but Eclipse gives me an InstantiationException and I don’t know why. How can I fix this?

Here is the Sms class code:

    public class Sms  {
        String message;
String phonenumber = "";
SharedPreferences  sp;
Context context;

        public Sms(String m, Context context)
        {

            message = m;
            this.context = context;
        } 

     public void sendSms()
        {
            sp  = PreferenceManager.getDefaultSharedPreferences(context);
               phonenumber = sp.getString("PHONE", "");


            SmsManager manager = SmsManager.getDefault();

            PendingIntent piSend = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0);
            PendingIntent piDelivered = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0);



                    int length = message.length();

                    if(length > MAX_SMS_MESSAGE_LENGTH)
                    {
                            ArrayList<String> messagelist = manager.divideMessage(message);

                            manager.sendMultipartTextMessage(phonenumber, null, messagelist, null, null);
                    }
                    else
                    {
                            manager.sendTextMessage(phonenumber, null, message, piSend, piDelivered);
                    }

        }
    }

--------------------------------------------

And the LogCat:

02-16 17:20:26.579: E/AndroidRuntime(474): FATAL EXCEPTION: main
02-16 17:20:26.579: E/AndroidRuntime(474): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{mioc.programing.safetpin/mioc.programing.safetpin.Sms}: java.lang.InstantiationException: mioc.programing.safetpin.Sms
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.os.Looper.loop(Looper.java:123)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-16 17:20:26.579: E/AndroidRuntime(474):  at java.lang.reflect.Method.invokeNative(Native Method)
02-16 17:20:26.579: E/AndroidRuntime(474):  at java.lang.reflect.Method.invoke(Method.java:507)
02-16 17:20:26.579: E/AndroidRuntime(474):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-16 17:20:26.579: E/AndroidRuntime(474):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-16 17:20:26.579: E/AndroidRuntime(474):  at dalvik.system.NativeStart.main(Native Method)
02-16 17:20:26.579: E/AndroidRuntime(474): Caused by: java.lang.InstantiationException: mioc.programing.safetpin.Sms
02-16 17:20:26.579: E/AndroidRuntime(474):  at java.lang.Class.newInstanceImpl(Native Method)
02-16 17:20:26.579: E/AndroidRuntime(474):  at java.lang.Class.newInstance(Class.java:1409)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
02-16 17:20:26.579: E/AndroidRuntime(474):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
02-16 17:20:26.579: E/AndroidRuntime(474):  ... 11 more

And this is how I create the object from my Activity:

Intent open_SM = new Intent ("android.intent.action.SMS");
            startActivity(open_SM);
    Sms s = new Sms("trlababalan",this);
            s.sendSms()

;

here is manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mioc.programing.safetpin"
    android:versionCode="1"
    android:versionName="1.0" >

      <uses-permission 
android:name="android.permission.ACCESS_FINE_LOCATION" /> 
  <uses-permission 
android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
  <uses-permission 
android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="mioc.programing.safetpin.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>

            <service android:name="TestService">
            </service>
             <activity
            android:name="mioc.programing.safetpin.Sms"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.SMS" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  • 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-18T22:47:49+00:00Added an answer on June 18, 2026 at 10:47 pm

    You have declared Sms as an Activity in your Manifest:

    <activity
        android:name="mioc.programing.safetpin.Sms"
        android:label="@string/app_name" >
    

    But Sms doesn’t extend Activity… So these lines cause the exception:

    Intent open_SM = new Intent ("android.intent.action.SMS");
    startActivity(open_SM);
    

    If you want to run Sms as an Activity you need to turn the entire class into an Android Activity, or if you want Sms to be a utility don’t use an Intent to start Sms as an Activity.

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

Sidebar

Related Questions

I have made a Java class where I have defined a constructor and some
How can I unit test my NSURLConnection delegate? I made a ConnectionDelegate class which
i recently made a cookie class but unfortunatly it wasn't really OOP because i
I made a class library, and put it in GAC. It has one C#
I made a class which looks something like. class NewInt: def __init__(self, x,y): self.holders
I have made an class which conforms to the NSCoding protocol and does all
So, I made a class that takes arrays and calculates a value from them.
I am learning C++ and I have a question. I made a class in
I made a form class in c# that has a devexpress grid, a label
I made a music class that will play a song. I have made onResume

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.