qwr qwr
qwr qwr

Reputation: 1059

An error during instantiate intent

I am totally new to android programming and I was reading a book called "Hello Android"

Basically the book teaches us Android by using a Sudoku game example.

Here is the main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/background"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:padding="30dip"
android:orientation="vertical" >
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center" >
<TextView
android:text="@string/main_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="25dip"
android:textSize="24.5sp" />
<Button
android:id="@+id/continue_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/continue_label" />
<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/new_game_label" />
<Button
android:id="@+id/about_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/about_label" />
<Button
android:id="@+id/exit_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/exit_label" />
</LinearLayout>
</LinearLayout>

Here is the string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sudoku</string>
<string name="main_title">Android Sudoku</string>
<string name="continue_label">Continue</string>
<string name="new_game_label">New Game</string>
<string name="about_label">About</string>
<string name="exit_label">Exit</string>
<color name="background">#3500ffff</color>
<string name="about_title">About Android Sudoku</string>
<string name="about_text">\
Sudoku is a logic-based number placement puzzle.
Starting with a partially completed 9x9 grid, the
objective is to fill the grid so that each
row, each column, and each of the 3x3 boxes
(also called <i>blocks</i>) contains the digits
1 to 9 exactly once.
</string>
</resources>

Here is the additional manifest to the old:

<activity android:name=".About"
android:label="@string/about_title" >
        </activity>

Here is the about.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" >
<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/about_text" />
</ScrollView>

And finally the Sudoku.java

package org.example.sudoku;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

public class Sudoku extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View continueButton = findViewById(R.id.continue_button);
        continueButton.setOnClickListener((OnClickListener) continueButton);

        View newButton = findViewById(R.id.new_button);
        newButton.setOnClickListener((OnClickListener) this);

        View aboutButton = findViewById(R.id.about_button);
        aboutButton.setOnClickListener((OnClickListener) this);

        View exitButton = findViewById(R.id.exit_button);
        exitButton.setOnClickListener((OnClickListener) this);


    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.about_button:
        Intent i = new Intent(this, About.class);   /** Here is the Error **/
        startActivity(i);
        break;
        // More buttons go here (if any) ...
        }
        }

}

Let me explain it a little bit. The Sudoku main page consists of 4 buttons, the book is teaching us to implement the button, so when the user presses it, the program will direct the user to the about page (which is just a page of text). The error happened on the About.class, Eclipse said that there is no such class called About. And I am not quite understand why there is an About.class in the intent argument as well....

And idea??

Upvotes: 1

Views: 76

Answers (3)

Samir Mangroliya
Samir Mangroliya

Reputation: 40416

you have class About.java in org.example.sudoku package?

public class About extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
 }
}

Upvotes: 1

Dheeresh Singh
Dheeresh Singh

Reputation: 15701

as per your comment ........ You must have the file About.java in you project and also add it's entry in the manifest...

<activity android:name=".About"
        android:label="@string/app_name">

    </activity>

so add About.java in parallel to Sudoku.java in your project and it also need to extends the Activity.........

Upvotes: 1

TPDev
TPDev

Reputation: 36

Did you write down your activity in the manifest, using the right or same package as your other activity?

http://developer.android.com/guide/topics/manifest/manifest-intro.html

Could you also please post your log cat?

Upvotes: 1

Related Questions