views:

43

answers:

1

My layout xml has a Tablelayout with TextViews for a cell:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow>
        <TextView
            android:text="Style Details..."
            android:padding="3dip" />

    </TableRow>
    <TableRow>
        <TextView
            android:text="Style"
            android:padding="3dip" />
        <TextView
            android:id="@+id/StyleName"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>

    <TableRow>
        <TextView
            android:text="Price (Euro)"
            android:padding="3dip" />
        <TextView
            android:id="@+id/StylePrice"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="Price for Volume &lt;60&lt;90 pcs"
            android:padding="3dip" />
        <TextView
            android:id="@+id/PriceVolume6090"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="Price for Volume &lt;100&lt;250pcs"
            android:padding="3dip" />
        <TextView
            android:id="@+id/PriceVoume100250"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="Price for Volume &lt;251&lt;500pcs"
            android:padding="3dip" />
        <TextView
            android:id="@+id/PriceVoume251500"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="Price for Volume &lt;501pcs"
            android:padding="3dip" />
        <TextView
            android:id="@+id/PriceVolume501"
            android:gravity="right"
            android:padding="3dip" />
    </TableRow>
</TableLayout>

I want to set the value for StyleName through my Activity. Following is the code that I am using:

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class StyleDetailsActivity extends Activity {
 private TextView tvStyleName;


 @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
                setContentView(R.layout.styledetailsview);
  String styleName = "Testing Style Name";
                tvStyleName = (TextView)findViewById(R.id.StyleName);
  tvStyleName.setText(styleName);


        }
}

The code is compiling fine and the app starts. On Running the app, I am getting a nullpointer exception. When I debug, I see that tvStyleName is null. Any suggestions as to why it would not be initializing

A: 

Solved the problem.

Changed: To:

Added a Item in Strings.xml for StyleName

related questions