7 Replies - 1065 Views - Last Post: 25 January 2013 - 10:04 PM

#1 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:32 PM

can some one help me out im trying the onclick android tutorial how how to change pages with a button but im stuck im getting an error that says the value of the field Main.Activity.b1 is not used i cant figure it out

 package com.example.lasttry;

            package com.example.lasttry;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.onclickListener;
import android.widget.Button;
import android.widget.EditText;
import android.content.Intent;


public class MainActivity extends Activity implements onclickListener  {
private Button b1;
public final static String EXTRA_MESSAGE = "com.example.lasttry";

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.setContentView(R.layout.activity_main);
        this.b1 = (Button)this.findViewById(R.id.b1);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onclick(View v) {
    finish();   // TODO Auto-generated method stub

    }
public void sendMessage(View v){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText= (EditText) findViewById(R.id.b1); 
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);


}

}


Is This A Good Question/Topic? 0
  • +

Replies To: the value of the field Main.Activity.b1 is not used error

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:35 PM

Moved to Android.

This sounds more like a warning than an error. Is there a yellow underline on Eclipse or a red underline marking the line in question?
Was This Post Helpful? 0
  • +
  • -

#3 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:36 PM

yellow
Was This Post Helpful? 0
  • +
  • -

#4 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:49 PM

well when i run the app and push the button nothing happens it just shuts off so i posted this up thinking that could be the prob
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:51 PM

Yellow is a warning. If the app is force quitting, check LogCat on Eclipse to view the error messages. Also, please properly indent your code.
Was This Post Helpful? 0
  • +
  • -

#6 ajrodelo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 14-January 13

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:53 PM

it dosnt show any errors
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 08:55 PM

Try closing the LogCat, reopening it, then running your program again. Sometimes the LogCat isn't always synced up with the emulator.
Was This Post Helpful? 0
  • +
  • -

#8 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,536
  • Joined: 29-July 11

Re: the value of the field Main.Activity.b1 is not used error

Posted 25 January 2013 - 10:04 PM

Did you declare DisplayMessageActivity.class in the manifest?

Also, when starting activities, try not to pas "this" in as a context. Use getApplicationContext(). When you pass this, the previous activity and everything it knows (its members) are completely ineligible for garbage collection for the entire lifecycle of the second activity. It consumes more memory and could slow things down.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1