0

I am fairly experienced with Java/Eclipse, but I'm entirely new to Android development and it's proven to be quite an odd beast so far. I'm currently trying to create an application with two image buttons. My XML is as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="@string/now_playing" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/StartButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/start_button"
            android:contentDescription="@string/start_button" />

        <ImageButton
            android:id="@+id/StopButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@drawable/stop_button"
            android:contentDescription="@string/stop_button" />

    </LinearLayout>

</LinearLayout>

This appears to be correct, but the ImageButtons do not render properly in the Graphical Layout tab and there is a message that says, "The following classes could not be found: - ImageButton (Change to android.widget.ImageButton, Fix Build Path, Edit XML)".

After looking around online a bit, I found that this question has popped up a few times on StackOverflow, but I was unable to find any satisfactory answers. The most common answer was to clean the project, but this has not done anything for me. Any suggestions?

user2871915
  • 469
  • 7
  • 17
  • Try cleaning / refreshing your project. Sometimes when you make large changes to xml in eclipse, you run into strange problems. – a person May 23 '14 at 23:33

2 Answers2

0

Sometimes the Eclipse Graphical layout tab is unable to draw stuffs whereas the code is fine. Try to run a simple Activity with setContentView(R.layout.yourxml); and see what happen :

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yourlayout);
    }
}

Post your LogCat if you still have errors.

EDIT : Oh and I didn't see :

On your second ImageButton, replace

android:text="@drawable/stop_button"

by

android:src="@drawable/stop_button"
Steel
  • 255
  • 2
  • 14
  • I don't have errors- the project will run. But in the Android simulator I see two gray buttons with no text instead of the images I have included. – user2871915 May 26 '14 at 00:17
0

Try to import the ImageButton class on java.

import android.widget.ImageButton;
sumaia111
  • 1
  • 1