November 25, 2012

Why isn't my Android program working?

Q. I am new to programming for the Android and am trying to write a relatively simple math program. I tried running the program in an emulator, but it hits an error upon start up. This happened after I added 2 other activities. I also changed the first activity in the manifest file (I decided I wanted a different activity to appear first). Could the problem lie in the manifest file, or is there some confusion with the spinner and the startActiviy? I have absolutely no idea what is wrong. Perhaps someone could walk me through using Eclipse's debugger or tell me what my error is (if its simple to see).

Here is the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.math.mathapp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".MainActivity.Main"> //This is what I changed
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Formulas"></activity>
<activity android:name=".Parabola"></activity>

</application>
</manifest>

Here is the Main.java:

public class Main extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Spinner spinner1 = (Spinner) findViewById(R.id.spinnermain);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.program_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);

spinner1.setOnItemSelectedListener(new programspinner());
}

public class programspinner implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
Intent intent = null;
String program;
program = parent.getItemAtPosition(pos).toString();
if(program=="Formula")
intent = new Intent(view.getContext(), Formulas.class);
if(program=="Parabola")
intent = new Intent(view.getContext(), Parabola.class);
startActivity(intent);
}
public void onNothingSelected(AdapterView parent) {
// Do nothing.
}
}
}


And here is the main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/blackbackground"
android:padding="10dip"
>
<ImageView android:src="@drawable/title"
android:layout_width="wrap_content"
android:id="@+id/imageView1"
android:layout_height="wrap_content"
android:layout_gravity="top"></ImageView>

<Spinner android:layout_width="match_parent"
android:id="@+id/spinnermain"
android:layout_height="wrap_content"
></Spinner>
</LinearLayout>

A.





Powered by Yahoo! Answers

No comments:

Post a Comment