我想在另一个类中的一个类中使用一个方法,我的代码没有任何错误,但是当我运行项目时,我得到“不幸的是项目*已停止”错误。当我复制方法而不是创建对象等时,我运行程序没有任何问题,谁能告诉我可能是什么问题?
public void onClick(View arg0) {
String p = "+989357835774";
String m = "test";
SendSMS sms = new SendSMS();
sms.sms(p, m);
}
public class SendSMS extends Activity {
public void sms (String phonno , String Message){
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SendSMS.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phonno, "+9891100500", Message , pi, null);
}
}
这些是我的错误:
08-23 19:31:00.065: E/AndroidRuntime(9985): FATAL EXCEPTION: main
08-23 19:31:00.065: E/AndroidRuntime(9985): java.lang.NullPointerException
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.content.ContextWrapper.getPackageName(ContextWrapper.java:127)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.content.ComponentName.<init>(ComponentName.java:75)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.content.Intent.<init>(Intent.java:3655)
08-23 19:31:00.065: E/AndroidRuntime(9985): at com.example.finalproject3.SendSMS.sms(SendSMS.java:15)
08-23 19:31:00.065: E/AndroidRuntime(9985): at com.example.finalproject3.Pizza$1$2.onClick(Pizza.java:53)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.view.View.performClick(View.java:4101)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.view.View$PerformClick.run(View.java:17078)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.os.Handler.handleCallback(Handler.java:615)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.os.Looper.loop(Looper.java:155)
08-23 19:31:00.065: E/AndroidRuntime(9985): at android.app.ActivityThread.main(ActivityThread.java:5485)
08-23 19:31:00.065: E/AndroidRuntime(9985): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 19:31:00.065: E/AndroidRuntime(9985): at java.lang.reflect.Method.invoke(Method.java:511)
08-23 19:31:00.065: E/AndroidRuntime(9985): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
08-23 19:31:00.065: E/AndroidRuntime(9985): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:795)
08-23 19:31:00.065: E/AndroidRuntime(9985): at dalvik.system.NativeStart.main(Native Method)