gpt4 book ai didi

Android应用程序在按钮单击时不断崩溃

转载 作者:行者123 更新时间:2023-12-03 17:45:00 25 4
gpt4 key购买 nike

我查看了其他问题和答案,但找不到我的代码有什么问题?
我一定是做错了什么,所以如果有人可以帮助我,将不胜感激。
我检查了第一页和第二页以及 list 。

package com.example.fmf;

import com.example.fmf.Search;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Spinner;
import android.view.View.OnClickListener;


public class MainActivity extends Activity {






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

Button button = (Button) findViewById(R.id.go_button);

button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
goMenu();
}

});
}


public void goMenu()
{
Intent myIntent = new Intent(this, Search.class);
startActivity(myIntent);
}


@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;
}

}

第2页
package com.example.fmf;


import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.Spinner;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;

public class Search extends Activity {



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
// Show the Up button in the action bar.
setupActionBar();
}

/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.search, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up- vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

Bundle extras = getIntent().getExtras();
public final String ID_CITY = extras.getString("CITY_TH");

//retrieve list view value selected and store in variable restaurant
//Not sure how to do this...



}

显现


    <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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=".Search"
android:label="@string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".Info"
android:label="@string/app_name"
android:parentActivityName=".Search" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Search" />
</activity>
</application>

</manifest>

抱歉耽误了日志猫(不知道如何发布所有内容)
11-27 15:40:05.118: D/AndroidRuntime(771): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-27 15:40:05.128: D/AndroidRuntime(771): CheckJNI is ON
11-27 15:40:05.158: D/dalvikvm(771): Trying to load lib libjavacore.so 0x0
11-27 15:40:05.168: D/dalvikvm(771): Added shared lib libjavacore.so 0x0
11-27 15:40:05.198: D/dalvikvm(771): Trying to load lib libnativehelper.so 0x0
11-27 15:40:05.198: D/dalvikvm(771): Added shared lib libnativehelper.so 0x0
11-27 15:40:05.278: E/cutils-trace(771): Error opening trace file: No such file or directory (2)
11-27 15:40:05.868: D/AlertService(549): Beginning updateAlertNotification
11-27 15:40:05.898: D/AndroidRuntime(771): Calling main entry com.android.commands.am.Am
11-27 15:40:05.918: D/dalvikvm(771): Note: class Landroid/app/ActivityManagerNative; has 163 unimplemented (abstract) methods
11-27 15:40:05.948: I/ActivityManager(286): Force stopping package com.example.fmf appid=10048 user=-1
11-27 15:40:05.959: I/ActivityManager(286): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.fmf/.MainActivity} from pid 771
11-27 15:40:06.328: I/WindowManager(286): Screenshot max retries 4 of Token{419849f0 ActivityRecord{41984880 u0 com.android.launcher/com.android.launcher2.Launcher}} appWin=Window{419646b0 u0 com.android.launcher/com.android.launcher2.Launcher} drawState=4
11-27 15:40:06.328: W/WindowManager(286): Screenshot failure taking screenshot for (480x800) to layer 21000
11-27 15:40:06.338: D/AndroidRuntime(771): Shutting down VM
11-27 15:40:06.348: D/dalvikvm(771): GC_CONCURRENT freed 92K, 16% free 513K/608K, paused 1ms+0ms, total 11ms
11-27 15:40:06.358: D/AlertService(549): No fired or scheduled alerts
11-27 15:40:06.388: W/dalvikvm(783): PR_CAPBSET_DROP 0 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.
11-27 15:40:06.388: W/dalvikvm(783): PR_CAPBSET_DROP 1 failed: Invalid argument. Please make sure your kernel is compiled with file capabilities support enabled.

最佳答案

如果没有堆栈跟踪,可能很难说。据我所知,你有两个可能的罪魁祸首。

第一

Bundle extras = getIntent().getExtras();
public final String ID_CITY = extras.getString("CITY_TH");

在您的 Search 类中,您试图从 bundle 中获取数据。但是在您的 MainActivity.goMenu() 中,您没有传递 bundle 。这可能会导致 NULLPOINTEREXCEPTION
第二
setupActionBar();

请尝试在您的 Search.class 中将其注释掉,看看结果如何。我从 list 中看不到您的主题是什么。因此,您甚至可能没有可能导致崩溃的操作栏。因此,如果注释掉上面的行有效,请将以下内容添加到您的 list 中:

改变:
android:theme="@style/AppTheme"

到:
android:theme="@android:style/Theme.Holo"

看看这是否有效。

关于Android应用程序在按钮单击时不断崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20250979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com