0

So I am working on an app and my app keeps stopping unexpectedly. Here is my code and manifest file:

MainActivity

package com.example.lasic;

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

public class MainActivity extends Activity {

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


    @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;
    }
    public void goNext(View view) {
        startActivity(new Intent(this,QuestionActivity.class));
    }

}

QuestionActivity

package com.example.lasic;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class QuestionActivity extends Activity{
    private int counter = 1;
    private UserScanner scanner = new UserScanner();
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.firstq);
        loadNext();
    }
    public void loadNext() {
        TextView view1 = (TextView) findViewById(R.id.textView1);
        view1.setText(scanner.questionList.get(counter));
        Button button1 = (Button) findViewById(R.id.button1);
        button1.setText(scanner.left.get(counter));
        Button button2 = (Button) findViewById(R.id.button2);
        button2.setText(scanner.centerLeft.get(counter));
        Button button3 = (Button) findViewById(R.id.button3);
        button3.setText(scanner.center.get(counter));
        Button button4 = (Button) findViewById(R.id.button4);
        button4.setText(scanner.centerRight.get(counter));
        Button button5 = (Button) findViewById(R.id.button5);
        button5.setText(scanner.right.get(counter));
        counter = counter + 1;
    }
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lasic"
    android:versionCode="1" android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <application
        android:debuggable = "true"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.lasic.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity 
          android:name="com.example.lasic.QuestionActivity" 
          android:label="EntrySurvey" >
        </activity>
    </application>
</manifest>

When I try to switch from MainActivity to QuestionActivity using goNext() method, I get "this app stopped unexpectedly error". How do I fix this please?

codeMagic
  • 44,549
  • 13
  • 77
  • 93
Manav Dutta
  • 171
  • 1
  • 1
  • 9
  • 4
    could you post LOGCAT errors ? – mohammed momn Feb 17 '14 at 03:01
  • Where is the logcat error? – Luis Pena Feb 17 '14 at 03:11
  • In your logcat. If you run adb logcat at a command line or look at the logcat tab in Eclipse you can see the log. It will have a full stack trace with the exception and context there. – Gabe Sechan Feb 17 '14 at 03:43
  • I'm assuming it is a problem with your `UserScanner` class. You sure it is initialized before going into your `loadNext()` method? For getting LogCat up and running - http://stackoverflow.com/questions/3280051/how-to-enable-logcat-console-in-eclipse-for-android – nathansizemore Feb 17 '14 at 04:12

2 Answers2

2

You Try This in goNext method

{

     Intent intent = new Intent(MainActivity.this ,QuestionActivity.class);
     startActivity(intent);

}

And in manifest file just give android:name=".QuestionActivity" is enough

Kunu
  • 5,078
  • 6
  • 33
  • 61
user3251646
  • 278
  • 4
  • 15
  • You should clean up your answer some. Only put code in the code blocks and explain *what* you have changed and *why* you believe it is the correct answer. – codeMagic Feb 17 '14 at 04:22
0

I don't think that there is any error in this line:

startActivity(new Intent(this,QuestionActivity.class));

It is correct. Are you sure there is not any error in your layout file? For example when you are not define android:layout_width or android:layout_height for the button you may get "this app stopped unexpectedly error". So check your layout file.

Zusee Weekin
  • 1,348
  • 2
  • 18
  • 41