Question

"FC Source not found on launch 1" asks my question, but the "answer" given is almost perfectly useless.

I have a program that contains two ImageViews. When I fire it up, I see both my images on my tablet. So far, so good.

Adding one line of code, defining 'coil_image,' means it will no longer load. There is no error message, it just apologizes for having stopped. If I fire it up by hitting F11, I get the "Source not found" error.

Does anyone have a useful answer telling me what I need to do to get past this point?

public class MainActivity extends Activity {

    ImageView coil_image = (ImageView) findViewById(R.id.imageInductionCoil);

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

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"
    android:background="@android:color/black"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/imageInductionCoil"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="300dp"
        android:minHeight="48dp"
        android:minWidth="48dp"
        android:src="@drawable/coil_green" />

    <ImageView
        android:id="@+id/imageFuelGauge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:minHeight="125dp"
        android:minWidth="125dp"
        android:src="@drawable/fuel_gauge" />

</RelativeLayout>
Was it helpful?

Solution

You first need to set your layout for your activity to be able to search for your elements on that layout. Simple try this:

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

   ImageView coil_image = (ImageView) findViewById(R.id.imageInductionCoil);

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top