2010-10-15 104 views
0

我在這方面還很新,但這應該是一個簡單的問題和答案。我試圖只做一個按鈕,而且我在佈局管理器中這樣做了。我試圖在代碼中實現它,但MotoDev不會識別屬於android.widget包的Button類。我想我只需要做一些類似於導入的東西,但我無法追查那是什麼。任何幫助,將不勝感激。MotoDev不識別Button類?

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

也許我不明白的問題,但我能想到的唯一的事情就是加入這一行:

import android.widget.Button; 
+0

我試過了,它不會允許它,因爲它是一個包。感謝您的幫助。至少我知道我並不是唯一一個認爲導入應該修復它的人。 – Geeklat 2010-10-16 13:20:38

+0

如何android.widget。*; – Eliseo 2010-10-20 14:38:54

0

我敢肯定禮有它的權利。 MOTODEV Studio不應該對SDK中的任何Android類做任何事情。如果您右鍵單擊每條線的錯誤,則可能會出現「快速修復」,從而確定正確的導入。此外,還有一個菜單項目「組織進口」,可以一次將它們全部拉入。這些是核心Eclipse IDE中的功能,並非MOTODEV獨有的功能。

但是,如果您認爲這是MOTODEV Studio的問題,請登錄developer.motorola.com上的論壇,我們將與您合作解決問題。

埃裏克

+0

我會看看組織導入或快速修復的東西的工作。我仍然習慣於Eclipse環境開發。在此之後,我可能不得不將一些東西發送到MotoDev論壇。我已經遇到無法輸入strings.xml文件的問題,因爲它會彈出一個不正確的錯誤,每個鍵入的鍵都會得到修補。謝謝btw – Geeklat 2010-10-16 13:22:11