0

I have 3 classes in my android project:

  1. Launch.java
  2. SmsReceiver.java
  3. StartActivity.java

Launch.java is as follows:-

package alertApp;

import com.alertapp.R;
import android.app.Activity;
import android.os.Bundle;

public class Launch extends Activity {      
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.launcher);
        }

}

SmsReceiver class uses broadcast receiver to access incoming messages and fires an intent to the StartActivity class.

EDIT: this is the SmsReceiver class:

    package alertApp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;



    public  class SmsReceiver extends BroadcastReceiver {
        //String number = "+919561356345";
        String number = "LM-WAYSMS";
        String sender, body;

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Bundle extras = intent.getExtras();
        if(extras == null)
            return;
        Object[] pdus = (Object[]) extras.get("pdus");
         for (int i = 0; i <  pdus.length; i++) {
             SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
             sender = SMessage.getOriginatingAddress().toString();
             body = SMessage.getMessageBody().toString();
             Toast.makeText(context, "From : " +sender + "\n Message : " +body, Toast.LENGTH_LONG).show();
         }

         if(sender.contentEquals(number)){
              Intent open = new Intent(context, StartActivity.class);
              open.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              open.putExtra("body", body);
              open.putExtra("number", number);
              context.startActivity(open);
         }
    }

}

EDIT: updated manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alertapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />
 <uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
     <activity
        android:name="com.alertapp.Launch"
        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="com.alertapp.StartActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.example.testapp.NextActivity" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
     <receiver
        android:name="com.alertapp.SmsReceiver"
        android:permission="android.permission.BROADCAST_SMS"
        android:enabled="true"> 
        <intent-filter>
            <action android:name = "android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

when i run the program by connecting my phone, it shows me fatal exception error.

    07-02 19:41:46.512: E/AndroidRuntime(10003): FATAL EXCEPTION: main
07-02 19:41:46.512: E/AndroidRuntime(10003): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.alertapp/com.alertApp.Launch}: java.lang.ClassNotFoundException: com.alertApp.Launch
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.os.Looper.loop(Looper.java:137)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread.main(ActivityThread.java:4517)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at java.lang.reflect.Method.invokeNative(Native Method)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at java.lang.reflect.Method.invoke(Method.java:511)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at dalvik.system.NativeStart.main(Native Method)
07-02 19:41:46.512: E/AndroidRuntime(10003): Caused by: java.lang.ClassNotFoundException: com.alertApp.Launch
07-02 19:41:46.512: E/AndroidRuntime(10003):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
07-02 19:41:46.512: E/AndroidRuntime(10003):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
07-02 19:41:46.512: E/AndroidRuntime(10003):    ... 11 more
newbee
  • 409
  • 2
  • 12
  • 34

1 Answers1

3

that is the package of Launch:

package alertApp;

and that you have defined in your xml:

<activity
    android:name="com.alertApp.Launch"
    android:label="@string/app_name" >

Looks like you have the wrong packagename in your activity definition.

nano_nano
  • 12,351
  • 8
  • 55
  • 83
  • yes.. there was an error in this. i have changed my manifest. But the problem is still not solved. Logcat shows the same error message – newbee Jul 02 '13 at 15:03