Eclipse Android App - The Application has stopped unexpectedly. Please try again -


i have problem application android (telephonymanager service). when run app code without getters works, if use get() function app send me message "the application has stopped unexpectedly. please try again". don't know what's wrong.

my "bad" code:

package com.example.tc;  import android.support.v7.app.actionbaractivity; import android.support.v7.app.actionbar; import android.support.v4.app.fragment; import android.telephony.telephonymanager; import android.content.context; import android.os.bundle; import android.view.layoutinflater; import android.view.menu; import android.view.menuitem; import android.view.view; import android.view.viewgroup; import android.widget.textview; import android.os.build;  public class tc1 extends actionbaractivity {  textview textview1;  @override protected void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_tc1);      if (savedinstancestate == null) {         getsupportfragmentmanager().begintransaction()                 .add(r.id.container, new placeholderfragment()).commit();     }      textview1=(textview)findviewbyid(r.id.textview1);        //get instance of telephonymanager       telephonymanager  tm=(telephonymanager)getsystemservice(context.telephony_service);           //calling methods of telephonymanager returns information      //if remove code app works      string imeinumber=tm.getdeviceid();      }  @override public boolean oncreateoptionsmenu(menu menu) {      // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.tc1, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();     if (id == r.id.action_settings) {         return true;     }     return super.onoptionsitemselected(item); }  /**  * placeholder fragment containing simple view.  */ public static class placeholderfragment extends fragment {      public placeholderfragment() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_tc1, container,                 false);         return rootview;     } } 

}

layout.activity_tc1.xml:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.tc.tc1" tools:ignore="mergerootframe" /> 

layout.fragment_tc1.xml:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context="com.example.tc.tc1$placeholderfragment" >      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="phone details:" />      <edittext         android:id="@+id/edittext1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_below="@+id/textview1"         android:layout_centerhorizontal="true"         android:layout_margintop="68dp"         android:ems="10"         android:text="aaaa" >          <requestfocus />     </edittext>  </relativelayout> 

androidmanifest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.tc"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="19" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.tc.tc1"             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> 

the official documentation getdeviceid says

returns unique device id, example, imei gsm , meid or esn cdma phones. return null if device id not available.   **requires permission: read_phone_state** 

you have not given read_phone_state permission in manifest file.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -