Issue
Activity that I want to go
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:text="hi"/>
</LinearLayout>
Main Activity
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="@+id/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="x"/>
</LinearLayout>
Java (has unknown entity error)
package com.mycompany.myapp2;
import android.app.*;
import android.os.*;
import android.view.*;
import android.content.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void x(View view) {
Intent intent = new Intent(this, another.class);
startActivity(intent);
}
}
I'm trying to make an activity go to another activity, but for some reason it doesn't work. I was expecting it to work, like it should with everyone Please help it has error "unknown entity" and I don't know why.
Solution
Answer # 1
If you want to move to another activity
class AnotherActivity extends extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.another);
}
}
you must extend your class "AnotherActivity.class" with "Activity" and override onCreate method
Answer # 2
public void x(View view) {
setContentView(view)
// OR
setContentView(R.layout.another)
}
Answered By - Sohaib Ahmed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.