Cześć,
mam prosty program pod android. Problem w tym że gdy go odpalam to aplikacja się crashuje i zamyka. Dlaczego tak się dzieje? Oto kod:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity = "true">
<activity
android:name=".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=".NowaAktywnosc"
android:label="@string/app_name">
</activity>
</application>
</manifest>
MainActivity.java:
package com.mycompany.myapp;
import android.app.*;
import android.os.*;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
Button przycisk = (Button) findViewById(R.id.przycisk);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
przycisk.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
Intent intencja = new Intent(MainActivity.this, NowaAktywnosc.class);
startActivity(intencja);
}
});
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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/przycisk"
android:text="@string/przycisk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
NowaAktywnosc.java:
package com.mycompany.myapp;
import android.os.*;
import android.app.*;
public class NowaAktywnosc extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.nowa);
}
}
nowa.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/napis"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/napis"/>
</LinearLayout>