gpt4 book ai didi

java - 如何修复 Android 上应用程序启动时崩溃的问题

转载 作者:行者123 更新时间:2023-12-02 04:37:42 25 4
gpt4 key购买 nike

我对 Android 应用程序开发还是新手,现在我遇到了这个崩溃并且无法修复

list 文件详细信息

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.outsource.ecg"
android:versionCode="1"
android:versionName="0.1" >

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ecg_mobile"
android:label="@string/ecg_client_title" >
<activity
android:name="com.outsource.ecg.app.MainActivity"
android:label="@string/ecg_client_title"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.outsource.ecg.app.RTEcgChartActivity"
android:label="@string/rt_ecg_chart_title"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.outsource.ecg.app.EcgLoadHistoryActivity"
android:label="@string/load_user_history_title"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.outsource.ecg.app.DeviceListActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/select_device"
android:screenOrientation="portrait"/>
<activity
android:name="com.outsource.ecg.app.EcgUserManageActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/user_manager_title"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.outsource.ecg.ECG_MANAGER_MANAGE" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.outsource.ecg.app.CreateNewUserActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/new_user_title"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.outsource.ecg.ECG_NEW_USER" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.outsource.ecg.app.EcgUserHistroyRecordActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/view_histroy_records_title"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.outsource.ecg.VIEW_HISTORY_RECORDS" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<receiver android:name="com.outsource.ecg.app.SDcardMountReceiver" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.MEDIA_UNMOUNTED" />
<action android:name="android.intent.action.MEDIA_SCANNER_STARTED" />
<action android:name="android.intent.action.MEDIA_REMOVED" />
<action android:name="android.intent.action.MEDIA_BAD_REMOVAL" />
<data android:scheme="file" />
</intent-filter>
</receiver>
</application>

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

</manifest>

任何人都可以帮我解决这个问题吗?它非常沮丧,因为我看不出哪里会出错。该应用程序的重点是将心电图信号获取到应用程序,绘制并存储它 ***编辑:添加appEntryAdapter

public static class AppEntryAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private Context mContext;
private ArrayList<AppEntry> mAppEntries;

public AppEntryAdapter(Context context, ArrayList<AppEntry> entries) {
mContext = context;
mAppEntries = entries;
mInflater = LayoutInflater.from(context);
}

这是 mainActivity 中的第 137 行和第 138 行

final AppEntry entry = mAppEntries.get(arg0);
appButton.setText(mContext.getString(entry.displayNameResID()));

_---------------------------------------- ----------------R.字符串:

   public static final class string {
public static final int ID_label=0x7f040032;

公共(public)静态最终 int about_app=0x7f040001;

字符串.xml

<?xml version="1.0" encoding="utf-8"?>

<string name="app_name">EcgMobile</string>
<string name="about_app">About ECG Mobile</string>
<string name="app_info">ECG Mobile\nDeveloped by:chv960@mail.usask.ca</string>

<string name="bt_not_enabled_leaving">Bluetooth is not enabled, exit!</string>


<!-- Options Menu -->
<string name="secure_connect">Connect a device - Secure</string>
<string name="insecure_connect">Connect a device - Insecure</string>
<string name="discoverable">Make bluetooth discoverable</string>

<!-- DeviceListActivity -->
<string name="scanning">scanning for devices...</string>
<string name="select_device">select a device to connect</string>
<string name="none_paired">No devices have been paired</string>
<string name="none_found">No devices found</string>
<string name="title_paired_devices">Paired Devices</string>
<string name="title_other_devices">Other Available Devices</string>
<string name="button_scan">Scan for devices</string>
<string name="title_connecting">connecting...</string>
<string name="title_connected_to">connected to </string>
<string name="title_not_connected">not connected</string>
<string name="not_connected">You are not connected to a device</string>

<!-- ECG control buttons -->
<string name="start_label">Start</string>
<string name="stop_label">Stop</string>
<string name="save_label">Save</string>
<string name="load_label">Load</string>
<string name="select">Select</string>
<string name="delete">Delete</string>
<string name="send">Send</string>
<!-- ECG user prompts -->
<string name="external_storage_unmounted_prompt">Please ensure external storage(such as SDCard) is mounted! :)</string>

<!-- Strings for Test -->
<string name="test_connection_status">Status:Disconnected</string>
<!-- Strings for Adding new ECGUser -->

<string name="add_user">New User</string>
<string name="name_label">Name:</string>
<string name="birth_label">Birth:</string>
<string name="commit_new_user_info">Save</string>

<!-- Strings for Titles -->
<string name="user_manager_title">ECGUser Management</string>
<string name="new_user_title">Create a new ECGUser</string>
<string name="view_histroy_records_title">History ECG Records</string>
<string name="ecg_server_title">ECG Mobile Server</string>
<string name="ecg_client_title">ECG Mobile Control Center</string>
<string name="load_user_history_title">ECG User History/string>
<string name="rt_ecg_chart_title">Realtime ECG Chart</string>

<!-- Connection Status -->
<string name="connected">Status:\nConnected</string>
<string name="connecting">Status:\nDisconnected</string>
<string name="none">Status:\nDisconnected</string>
<string name="listen">Status:\nListening</string>
<string name="name_item_empty">Name is empty, please retry!</string>
<string name="create_new_user_failed">Create new user failed!</string>
<string name="male_label">male</string>
<string name="female_label">female</string>
<string name="select_valid_user">Please select a valid ecg user!</string>
<string name="not_recv_any_data">Don\'t have received any valid data, do nothing!</string>
<string name="new_user_created_debug">A new user record was created!</string>
<string name="target_device_not_connected">Target device is not connected!</string>
<string name="ID_label">ID:</string><string name="gender_label">gender:</string>
<string name="enroll_date_label">Enroll Date:</string>
<string name="age_label">Age:</string>
<string name="ecg_data_path_label">ECG DataPath:</string>
<string name="hbr_label">HBR:</string>
<string name="load_history_entry">View User History Record</string>
<string name="rt_ecg_chart">Realtime ECG Chart</string></string>

---------------appEntryAdapter的getview

public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ViewGroup app_entry = (ViewGroup) mInflater.inflate(
R.layout.app_entry_item, null);
Button appButton = (Button) app_entry.findViewById(R.id.app);
final AppEntry entry = mAppEntries.get(arg0);
appButton.setText(mContext.getResources().getString(R.string.load_history_entry));

appButton.setOnClickListener(new View.OnClickListener() {

08-12 15:01:59.763: W/ResourceType(622): Failure getting entry for 0x7f040038 (t=3 e=56) in package 0 (error -75)
08-12 15:01:59.763: D/AndroidRuntime(622): Shutting down VM
08-12 15:01:59.772: W/dalvikvm(622): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-12 15:01:59.782: E/AndroidRuntime(622): FATAL EXCEPTION: main
08-12 15:01:59.782: E/AndroidRuntime(622): android.content.res.Resources$NotFoundException: String resource ID #0x7f040038
08-12 15:01:59.782: E/AndroidRuntime(622): at android.content.res.Resources.getText(Resources.java:201)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.content.res.Resources.getString(Resources.java:254)
08-12 15:01:59.782: E/AndroidRuntime(622): at com.outsource.ecg.app.MainActivity$AppEntryAdapter.getView(MainActivity.java:138)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.ListView.onMeasure(ListView.java:1127)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.View.measure(View.java:8313)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.View.measure(View.java:8313)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.View.measure(View.java:8313)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.View.measure(View.java:8313)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.View.measure(View.java:8313)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.os.Looper.loop(Looper.java:123)
08-12 15:01:59.782: E/AndroidRuntime(622): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-12 15:01:59.782: E/AndroidRuntime(622): at java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:01:59.782: E/AndroidRuntime(622): at java.lang.reflect.Method.invoke(Method.java:507)
08-12 15:01:59.782: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-12 15:01:59.782: E/AndroidRuntime(622): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-12 15:01:59.782: E/AndroidRuntime(622): at dalvik.system.NativeStart.main(Native Method)
08-12 15:02:02.223: I/Process(622): Sending signal. PID: 622 SIG: 9

我找到了解决方案。因为有 2 个 STRING.XML 文件(出于某种我不知道的原因),它们被 IDE 混淆了。当我删除 1 时,它就起作用了非常感谢大家帮助我:)

最佳答案

从日志中可以清楚地看出问题:您正在尝试检索不可用的字符串资源。最有可能的是,您使用了拼写错误的 ID。首先查看 MainActivity.java:138 并查看您想要获取的字符串 ID。

还要检查布局 XML - 可能您已经为正在加载的 View 定义了一些文本,但该文本的字符串在您的资源中不存在。

关于java - 如何修复 Android 上应用程序启动时崩溃的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25257415/

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