我对 Android 应用程序有疑问。当我尝试通过 buttun 从主要活动 (PretvornikValut) 切换到另一个 (Pretvornik) 时,我收到“不幸的是应用程序停止工作”错误。任何人都可以帮忙吗?
PretvornikValut.java
package pretvornik.valut;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class PretvornikValut 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 gumbPretvori = findViewById(R.id.gumb_pretvornik);
gumbPretvori.setOnClickListener(this);
View gumbTecaji = findViewById(R.id.gumb_tecaji);
gumbTecaji.setOnClickListener(this);
}
public void sendMessage(View view) {
Intent intent = new Intent(this, Pretvornik.class);
startActivity(intent);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.gumb_pretvornik:
Intent i = new Intent(this, Pretvornik.class);
//i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
break;
case R.id.gumb_tecaji:
Intent tecaj = new Intent(this, Tecaji.class);
tecaj.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(tecaj);
break;
}
}
}
普雷特沃尼克 java
package pretvornik.valut;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
/**
*
* @author FAKS
*/
public class Pretvornik extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.pretvornik);
}
}
主要的.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="#99CCCC"
>
<Button
android:id="@+id/gumb_pretvornik"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="Pretvornik"
/>
<Button
android:id="@+id/gumb_tecaji"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toRightOf="@+id/OK"
android:layout_alignParentBottom="true"
android:text="Izpis tecajev"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Izberi zeljeno opcijo"
/>
</LinearLayout>
pretvornik.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="#99CCCC"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="glavni program"
/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pretvornik.valut"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="PretvornikValut"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity
android:name="Pretvornik"
android:label="@string/Pretvornik_valut" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
<activity
android:name="Tecaji"
android:label="@string/Izpis_tecajev" >
<meta-data
android:name="PretvornikValut"
/>
</activity>
</activity>
</application>
</manifest>