HaSeeB MiR HaSeeB MiR - 5 months ago 34
Java Question

Android Application Crashes ActivityManager permission Denied on Eclipse

My Application is crashing every time when I Run it. only HelloWorld app runs fine.

It says Activity Manager permission denied. Please have a look.


Console :

1.[2016-04-18 17:21:21 - Demo] ActivityManager: open: Permission denied

1. [2016-04-18 17:21:21 - Demo] ActivityManager:

Starting: Intent
act=android.intent.action.MAIN cat=
[android.intent.category.LAUNCHER]
cmp=com.example.demo/.MainActivity


and here is my LogCat File..
Android LogCat

And Here is my MainActivity.java

public class MainActivity extends Activity implements OnClickListener {
EditText et = (EditText)findViewById(R.id.editText1);
Button btn = (Button)findViewById(R.id.button1);
TextView tv = (TextView)findViewById(R.id.textView1);

@Override
protected void onCreate(Bundle savedInstanceState) {
btn.setOnClickListener(this);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public void onClick(View v) {
tv.setText(et.getText().toString());
}}


and Here is my Manifest File.

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

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >

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

Answer

Ui is created in onCreate method of activity

public class MainActivity extends Activity implements OnClickListener {
     EditText et;
     Button btm;
     TextView tv;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          et = (EditText)findViewById(R.id.editText1);
          btm = (Button)findViewById(R.id.button1);
          tv = (TextView)findViewById(R.id.textView1);
          btm.setOnClickListener(this);
     }

     @Override
     public void onClick(View v) {
         if(v.getId==btm.getId()) tv.setText(et.getText().toString());
     }
}
Comments