2016-02-08 90 views
0

我正在處理我的第一個Android應用程序。這是一個非常簡單的farenheit /攝氏轉換器,我所有的ID,方法和按鈕/文本字段都被完美地複製出來。我三重檢查。 (我正在按照我的教授發佈的視頻中的說明進行操作)。然而,我很難嘗試讓Android Studio運行該應用程序。Android Studio(1.5.1) - 錯誤:無法找到符號類/應用程序無法運行

我發現很多類似這個問題的問題,其中很多人建議同步gradle文件。所以我做了。我仍然得到這些相同的錯誤信息:

enter image description here


這裏是應用信息:

enter image description here

從應用/ RES /佈局/ content_test.xml代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="john.testapplication.TestActivity" 
    tools:showIn="@layout/activity_test"> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:inputType="numberDecimal" 
     android:ems="10" 
     android:id="@+id/temperatureEditText" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:hint="Enter Temperature" /> 

    <RadioGroup 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/temperatureEditText" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:id="@+id/radioGroup"> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="From Celsius to Farenheit" 
      android:id="@+id/toFarenheitRadioButton" 
      android:checked="false" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="From Farenheit to Celsius" 
      android:id="@+id/toCelsiusRadioButton" 
      android:checked="false" /> 
    </RadioGroup> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Convert" 
     android:id="@+id/convertButton" 
     android:layout_below="@+id/radioGroup" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:onClick="convert" /> 
</RelativeLayout> 

來自app/res/layout的代碼/activitytest.xml: (我想我是用相對佈局,我不知道這有什麼與我的問題

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="john.testapplication.TestActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_test" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 

再次,我是建設從該應用程序視頻我的教練給了我,所以我敢打賭,它與我的Android Studio版本或我的電腦上的設置有關,而不是代碼本身。

+1

我知道'CoordinatorLayout'但沒有'** ** CoordinatorLayout'。 –

+2

打開TestActivity並按照紅色下劃線。你輸入了一切嗎? –

+0

好的...哎呀。我試圖在代碼中粗暴地表達這個詞,我不應該那樣做。這些星號不是問題的一部分,那就是我。我的錯。 –

回答

2

好的,在本網站某人的幫助下,我找到了一個解決方案。顯然在TestActivity.xml中,我忘了導入這些:

import android.widget.EditText; 
import android.widget.RadioButton; 

修復了一切。我曾以爲它已經全部導入。感謝Eugen Pechanec提供有用的提示。

1

確保您正在導入正確的庫。 也曾經正確導入

initialize radioButtons : 
RadioButton rd; 

onCreate方法:

rd = (RadioButton)findViewById(R.id.radioButton);

+0

你能不能澄清編輯應該在哪裏發生? – shawnr

+0

通常,爲了使對象在整個活動中可用,學習可以在課堂上進行。 'onCreate'方法將在'activity.class'內提供。 –

相關問題