tags:

views:

35

answers:

2

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 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
+2  A: 

Maybe I don't understand the question, but the only thing I can think of is adding this line:

import android.widget.Button;
Eli
I tried that and it won't allow it because it's a package. Thanks for the help though. At least I know that i'm not the only one thinking that importing should have fixed it.
Geeklat
How about android.widget.*;
Eli
A: 

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

Eric Cloninger
I'll see if the organize import or quick fix things work. I'm still getting used to Eclipse environment development. After this i'll probably have to send something off to the MotoDev forums. I've already had an issue with being unable to type in the strings.xml file because it would pop up an incorrect error with every key typed that ended up getting patched. Thanks btw
Geeklat