Hoping to get into android app development so I’m doing some basic tutorials just now.
Just trying to get comfortable with the basics at the moment, one of which is using the Typeface class.
package org.me.myandroidstuff;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class HelloWorldActivity extends Activity implements OnClickListener
{
private View mainView;
private TextView tbox1;
private Button exitButton;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainView=(View)findViewById(R.id.mainView);
mainView.setBackgroundColor(getResources().getColor(R.color.silver));
tbox1 = (TextView)findViewById(R.id.textBox1);
tbox1.setTypeface(Typeface.MONOSPACE);
}
}
The line
tbox1 = (TextView)findViewById(R.id.textBox1);
Has a red cross beside it (I’m using eclipse) with the error
tbox1 cannot be resolved
Its been a while since i have used java, but as i aware the following code
- create a new TextView object called tbox1
- Assigns the tbox1 object the id specified in the xml for the TextView tag in an external main.xml
- Then tbox1 executes the setTypeFace() method on itself?
Obviously I’m going wrong somewhere, any ideas? Something really simple no doubt…
You can’t inform us about one error and neglect the others. Look at your code.
Besides what user370305 said, you have other problems. Namely, your
Activity, according to the contract,implements OnClickListenerbut does not override the necessaryonClick(View v)method. You must add it for the contract to be met.So your code should look like:
Remember, you can’t talk about errors until you fix every other that might cause other errors to be falsely reported.