Soru & Cevap

Android Stüdyo Sms Has Stopped Hatası acil yardım lütfen ...

08.01.2016 - 06:49

Merhaba herkese sms gönderen basit bir uygulama yapmak istedim fakat sms göndermek için tıklayınız butonuna tıkladığım zaman Unfortunately, sms has stopped diye bir hata alıyorum.

 

Hatanın burada olduğunu düşünüyorum

Çözüm için şimdiden teşekkürler herkese.

 

01-08 16:43:25.246 2116-2116/com.example.sms E/AndroidRuntime: FATAL EXCEPTION: main
                                                               Process: com.example.sms, PID: 2116
                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sms/com.example.sms.MainActivity2}: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
                                                                   at com.example.sms.MainActivity2.onCreate(MainActivity2.java:46)
                                                                   at android.app.Activity.performCreate(Activity.java:6237)
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                   at android.os.Looper.loop(Looper.java:148) 
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

 

 

 

Benim yazdığım kod ise bu

 

package com.example.sms;

import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity2 extends AppCompatActivity {

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });


        Button gonder_btn = (Button) findViewById(R.id.button_gonder);
        final EditText numara = (EditText) findViewById(R.id.editText_numara);
        final EditText mesaj =(EditText) findViewById(R.id.editText_mesaj);

        gonder_btn.setOnClickListener(
                new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                smsgonder(numara.getText().toString(), mesaj.getText().toString());
                Toast.makeText(getApplicationContext(), "sms gönderildi", Toast.LENGTH_LONG).show();


            }
        });
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    private void smsgonder(String telno, String mesaj) {
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(telno, null, mesaj, null, null);
    }


    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "MainActivity2 Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.example.sms/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "MainActivity2 Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("android-app://com.example.sms/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }
}

 

12 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-11052-1576825910.jpg
alikarakoc
08.01.2016 - 10:56

Sorun XML de Textview olan elementi EditText olarak tanımlandığı içindi.

Sorun çözülmüştür.