android.view.InflateException: Binary XML file line #9: Error inflating class textView



I'm a beginner and new in android .I searched but not found any way to resolve my problem across the similar my problem... I have below Error when click the button that created in main_activity to show details in detail_activity... . can help me anybody? what i do wrong ?



09-05 08:59:09.210: E/AndroidRuntime(17989): FATAL EXCEPTION: main
09-05 08:59:09.210: E/AndroidRuntime(17989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.workwithdata/com.example.workwithdata.DetailsActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class textView


the MainActivity.java is :



package com.example.workwithdata;

import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;


import com.example.workwithdata.R;
import com.example.workwithdata.data.Flower;
import com.example.workwithdata.data.FlowerData;


public class MainActivity extends ActionBarActivity {

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

LinearLayout layout= (LinearLayout) findViewById(R.id.layout);
List<Flower> Flowers = new FlowerData().GetFlowers();

for (final Flower flower : Flowers) {

Button button=new Button(this);
button.setText(flower.flowerName);
layout.addView(button);

button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
intent.putExtra("flowerName", flower.flowerName);
intent.putExtra("imageResource", flower.imageResource);
intent.putExtra("instruction", flower.instructions);

startActivity(intent);
}
});
}

}




@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}


}


and DetailsActivity.java:



package com.example.workwithdata;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class DetailsActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);

Intent intent = getIntent();

if (intent !=null) {

String flowerName = intent.getStringExtra("flowerName");
int imageResource = intent.getIntExtra("imageResource", 0);
String instruction = intent.getStringExtra("instrucion");

TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(flowerName);

tv = (TextView) findViewById(R.id.textView2);
tv.setText(instruction);

ImageView IV = (ImageView) findViewById(R.id.image);
IV.setImageResource(imageResource);


}

}

}


and layout of main_activity.xml :



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout"
android:orientation="vertical">

</LinearLayout>


and layout of details_activity.xml:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical" >


<textView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textAppearance="?android:attr/textAppearanceLarge" >

</textView>

<imageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView1">

</imageView>

<textView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

</textView>


</LinearLayout>


Thanks in advance


No comments:

Post a Comment