Im a newbie in android development and thats why im asking you experts such a simple problem
I created a table view and it is working fine.
I tried to move to a new view when clicking on the first cell and for that i created a new file Newview.java.
But when clicking on the first cell app is crashing and showing the message “Unfortunately HelloTableLayout has stopped”.
Can anyone please help me with this.
HelloTableLayoutActivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class HelloTableLayoutActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView name = (TextView)findViewById(R.id.label);
name.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v) {
Intent nameActivity =new Intent();
nameActivity .setClass(getApplicationContext(), Newview.class);
startActivity(nameActivity);
}
});
}
}
Main.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<TableRow>
<TextView
android:layout_column="1"
android:text="@string/name"
android:padding="3dip" />
<TextView
android:text="@string/initial"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="@string/hometown"
android:padding="3dip" />
<TextView
android:text="@string/state"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
Newview.java
import android.app.Activity;
import android.os.Bundle;
public class Newview extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.foo);
}
}
HelloTableLayout Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sweans.tb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
>
<activity
android:label="@string/app_name"
android:name=".HelloTableLayoutActivity">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".NewviewActivity"
android:label="@string/app_name"
>
</activity>
</application>
</manifest>
foo.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
Can anyone please help me where im going wrong in my code and why the app is crashing.
Thanks in advance.
Please change the following code .
with the below code.
and define your Newview class in android manifest file.
Because as you call Newview from your main class and you declare NewviewActvity class in android manifest file , so when you click on textview at that time android finds the Newview class in android manifest file, because it not present in that manifest file your application goest to crash.