0

我目前正在运行一个用于接收消息的项目,但是当我即将运行我的应用程序时,它向我发送了一个致命异常,并且我的应用程序被强制关闭,并显示消息 com.project.SMSresponder 已停止运行。

日志猫:

06-21 11:57:24.188: D/AndroidRuntime(335): Shutting down VM
06-21 11:57:24.188: W/dalvikvm(335): threadid=1: thread exiting with uncaught exception (group=0x40015560)
06-21 11:57:24.208: E/AndroidRuntime(335): FATAL EXCEPTION: main
06-21 11:57:24.208: E/AndroidRuntime(335): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.project.smsresponder/com.project.SMSresponderActivity}: java.lang.ClassNotFoundException: com.project.SMSresponderActivity in loader dalvik.system.PathClassLoader[/data/app/com.project.smsresponder-1.apk]
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.os.Looper.loop(Looper.java:123)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-21 11:57:24.208: E/AndroidRuntime(335):  at java.lang.reflect.Method.invokeNative(Native Method)
06-21 11:57:24.208: E/AndroidRuntime(335):  at java.lang.reflect.Method.invoke(Method.java:507)
06-21 11:57:24.208: E/AndroidRuntime(335):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-21 11:57:24.208: E/AndroidRuntime(335):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-21 11:57:24.208: E/AndroidRuntime(335):  at dalvik.system.NativeStart.main(Native Method)
06-21 11:57:24.208: E/AndroidRuntime(335): Caused by: java.lang.ClassNotFoundException: com.project.SMSresponderActivity in loader dalvik.system.PathClassLoader[/data/app/com.project.smsresponder-1.apk]
06-21 11:57:24.208: E/AndroidRuntime(335):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-21 11:57:24.208: E/AndroidRuntime(335):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-21 11:57:24.208: E/AndroidRuntime(335):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
06-21 11:57:24.208: E/AndroidRuntime(335):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
06-21 11:57:24.208: E/AndroidRuntime(335):  ... 11 more
06-21 11:57:34.199: I/Process(335): Sending signal. PID: 335 SIG: 9

Maniseft.xml:

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

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Starting_point"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

java文件:

    public class Recieve extends BroadcastReceiver 
{

        String lsms;
        /* package */ static final String ACTION =
                "android.provider.Telephony.SMS_RECEIVED";

        private static final String TAG = "SMSBroadcastReceiver";
        private static final int MAX_SMS_MESSAGE_LENGTH = 0;


            @Override
            public void onReceive(Context context, Intent intent) {
                 //---get the SMS message passed in---       
                Log.i(TAG, "Intent recieved: " + intent.getAction());

                if (intent.getAction().equals(ACTION)) {

                Bundle bundle = intent.getExtras();               
                SmsMessage[] msgs = null;        
                String str = "";                    
                if (bundle != null)        {           
                    //---retrieve the SMS message received---            
                    Object[] pdus = (Object[]) bundle.get("pdus");            
                    msgs = new SmsMessage[pdus.length];                        
                    for (int i=0; i<msgs.length; i++){                
                        msgs[i] =  SmsMessage.createFromPdu((byte[])pdus[i]);                                
                        str += "SMS from " + msgs[i].getOriginatingAddress();                                     
                        str += " :";                
                        str += msgs[i].getMessageBody().toString();                
                        str += "\n";                    
                        }            
                    //---display the new SMS message---            
                    Toast.makeText(context, str,   
                        Toast.LENGTH_SHORT).show();        
                    }
            }

            }
    }

第二个:

        public class Stat extends Activity{

            Button btstat;

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
                 setContentView(R.layout.rtlayout);

                 btstat = (Button) findViewById(R.id.button1);

                    btstat.setOnClickListener(new View.OnClickListener() 
                    {

                        public void onClick(View v) 
                        {
                            // TODO Auto-generated method stub

                            Intent intent = new Intent(Stat.this,Recieve.class);                    
                        startActivity(intent);
                    }
                }); 
        }   
    }
4

2 回答 2

3
Caused by: java.lang.ClassNotFoundException: com.project.SMSresponderActivity 

com.project.SMSresponderActivity在清单上不见了。

<activity
    android:name=".SMSresponderActivity"
    android:label="@string/smsResponder_name" >
</activity>

您需要在清单中指定所有活动以及接收者。我看到您也没有它们(如@imran khan 所述)。

于 2012-06-21T07:35:55.183 回答
1

将您的Recieve BroadcastReciver 和Stat.javaActivity 在清单中注册为:

<receiver android:name=".Recieve" android:exported="true" > 
<intent-filter android:priority="999"> 
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter> 
</receiver>

<activity
    android:name=".Stat" />
 <activity
android:name=".SMSresponderActivity" />

清单文件中的使用权限:

<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

编辑:最后一个大错误是 Recieve 不是一个活动,它是广播接收器,或者你正在将它作为 Activity 启动,所以当任何新的短信接收时改变它,你的 Recieve 会自动启动

public void onClick(View v) 
                {
                  // TODO Auto-generated method stub

                  //Intent intent = new Intent(Stat.this,Recieve.class);
           Intent intent = new Intent(Stat.this,YOUR_NEXT_ACTIVITY.class); //you are passing Recieve here    
                        startActivity(intent);
                    }
于 2012-06-21T07:37:06.163 回答