MotoDev not recognizing Button class?
I'm still really new at this, but this should hopefully be a simple question and answer. I'm trying to just make a button and I've done so in the layout manager. I'm trying to implement it in code, but MotoDev won't recognize the Button class that's part of the android.widget package. I imagine I just have to do something similar to an import开发者_JAVA技巧 but I can't track down what that is. Any help would be appreciated.
package com.androidbook.myfirstandroidapp;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.location.Location;
import android.location.LocationManager;
import android.graphics.drawable.ColorDrawable;
public class MyFirstAndroidApp extends Activity
{
private static final String DEBUG_TAG= "MyFirstAppLogging";
private MediaPlayer mp;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myString = getResources().getString(R.string.hello);
int myColor = getResources().getColor(R.color.Red);
float myDimen = getResources().getDimension(R.dimen.textPointSize);
ColorDrawable myDraw = (ColorDrawable)getResources().getDrawable(R.drawable.redDrawable);
//Log.i(DEBUG_TAG, "Info about MyFirstAndroidApp");
setContentView(R.layout.buttons);
final Button basic_button = (Button) findViewById(R.id.basic_button);
}
public void callThisNumber()
{
Uri number = Uri.parse("tel:3045555555");
Intent dial = new Intent(Intent.ACTION_DIAL, number);
startActivity(dial);
}
public void forceError()
{
if(true)
{
throw new Error("Whoops");
}
}
public void playMusicFromWeb()
{
try
{
Uri file = Uri.parse("http://www.perlgurl.org/podcast/archives/podcasts/PerlgurlPromo.mp3");
mp = MediaPlayer.create(this, file);
mp.start();
}
catch(Exception e)
{
Log.e(DEBUG_TAG, "Player failed", e);
}
}
public void getLocation()
{
try
{
LocationManager locMgr = (LocationManager)getSystemService(LOCATION_SERVICE);
Location recentLoc = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Log.i(DEBUG_TAG, "loc: " + recentLoc.toString());
}
catch(Exception e)
{
Log.e(DEBUG_TAG, "Location Failed", e);
}
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
if(mp != null)
{
mp.stop();
mp.release();
}
super.onStop();
}
} // End Class
Maybe I don't understand the question, but the only thing I can think of is adding this line:
import android.widget.Button;
I'm pretty sure Eli has it right. MOTODEV Studio shouldn't be doing anything with any of the Android classes in the SDK. If you right click on the error for each line, there is a possibility of a "Quick Fix" that determines the right import. Also, there is a menu item to "Organize Imports" that pulls them all in at once. These are features that are in the core Eclipse IDE and not unique to MOTODEV.
But, if you think it's a problem with MOTODEV Studio, drop in to the forums at developer.motorola.com and we'll work with you to get it solved.
Eric
精彩评论