Antoine Dahan
Antoine Dahan

Reputation: 713

Onclick simple program giving logic error ( 'Unable to open stack trace file '/data/anr/traces.txt': Permission denied')

I am getting the error 'Unable to open stack trace file '/data/anr/traces.txt': Permission denied' which I know has somthing to do with error in the logic; the issue is my xml files are spic and span, therefore I assume it must be by activity class.

I have a main layout (main.xml) which has the buttons: 'start' and 'instructions'. When clicking the instructions button it should go to the layout: instructions.xml and when clicking the start button it should go to the layout: test_layout.xml.

For any insight what so ever I would be most grateful and pour millions of reputation on you. Thanks.

-Is the issue that I am implementing the OnClickListener ?

-Is it something to do not putting a @Override on top of the second method ('public void onClick')? because it says that I can only place it when overwriting a super class.**

Please, it very short code, I could appreciate if you could take a quick glance and tell me what you think. I posted the manifest bellow the code.

package it.will.work;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;



public class ActualWorkingQuizActivity extends Activity implements OnClickListener{


 Button start = (Button) findViewById(it.will.work.R.id.start_main);
 Button instructions = (Button) findViewById(it.will.work.R.id.instructions_main);


    /* Called when the activity is first created. */
       @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


     //sets the Click Listeners
    start.setOnClickListener(this);
    instructions.setOnClickListener(this); 

}

public void onClick(View v) {
     if (v==start) {
         setContentView(it.will.work.R.layout.test_layout);
     }
     else if (v==instructions) {
         setContentView(it.will.work.R.layout.instructions);
}
     }
     }

Here is my manifest.

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

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

   <application
       android:icon="@drawable/starwarsicon"
       android:label="@string/appname" >
       <activity
           android:label="@string/appname"
           android:name=".ActualWorkingQuizActivity" >
           <intent-filter >
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>

Upvotes: 0

Views: 761

Answers (1)

Arun Badole
Arun Badole

Reputation: 11097

Initialize your Buttons in onCreate().

start = (Button) findViewById(R.id.start_main);
instructions = (Button) findViewById(R.id.instructions_main);

In onClick() method make changes like this

public void onClick(View v)
{
    if (v.getId() == R.id.start_main)
    {
      setContentView(R.layout.test_layout);
    } else if (v.getId() == R.id.instructions_main)
    {
      setContentView(R.layout.instructions);
    }
}

Or Alternate

public void onClick(View v)
{
    if (v.equals(start))
    {
      setContentView(R.layout.test_layout);
    } else if (v.equals(instructions))
    {
      setContentView(R.layout.instructions);
    }
}

Upvotes: 2

Related Questions