当前位置: 首页 > 知识库问答 >
问题:

在Android Studio上运行应用程序时(应用程序崩溃)有关更多具体信息,请参阅描述

轩辕晔
2023-03-14

ApiTokenActivity。java(类)

package nl.empoly.android.safetysupport;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.json.JSONException;

import java.io.IOException;

import nl.empoly.android.safetysupport.api.ApiApitoken;
import nl.empoly.android.safetysupport.api.ApiAssignment;
import nl.empoly.android.safetysupport.api.ApiClient;
import nl.empoly.android.safetysupport.api.ApiClientLocation;
import nl.empoly.android.safetysupport.api.ApiContact;
import nl.empoly.android.safetysupport.api.ApiWarehouse;
import nl.empoly.android.safetysupport.entity.EntApitoken;
import nl.empoly.android.safetysupport.entity.EntAssignment;
import nl.empoly.android.safetysupport.entity.EntClient;
import nl.empoly.android.safetysupport.entity.EntClientLocation;
import nl.empoly.android.safetysupport.entity.EntContact;
import nl.empoly.android.safetysupport.entity.EntWarehouse;

public class ApiTokenActivity extends ActionBarActivity {

    ApiApitoken mApiApitoken;


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.apitoken_activity);
        final TextView editText = (TextView) findViewById(R.id.description);
        Button button = (Button) findViewById(R.id.create_button);
        final Button button1 = (Button) findViewById(R.id.delete_button);
        Button login_button = (Button) findViewById(R.id.login_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String description = editText.getText().toString();
                new CreateApiTokenTask().execute(description);
                button1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                new DeleteApiTokenTask().execute(mApiApitoken);

                    }
                });

            }
        });
        login_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ApiTokenActivity.this,LogInActivity.class));


            }
        });
    }


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


    }

    public class CreateApiTokenTask extends AsyncTask<String, Void, ApiApitoken> {

        @Override
        protected ApiApitoken doInBackground(String... params) {
            try {
                return ApiApitoken.create(params[0]);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(ApiApitoken ApiApitoken) {
            TextView ID = (TextView) findViewById(R.id.TAG_IDtv);
            TextView Description = (TextView) findViewById(R.id.TAG_Dtv);
            TextView Token = (TextView) findViewById(R.id.TAG_Ttv);
            TextView ExpiresAt = (TextView) findViewById(R.id.TAG_EAtv);
            TextView RefreshToken = (TextView) findViewById(R.id.TAG_RTtv);

            ID.setText(ApiApitoken.id);
            Description.setText(ApiApitoken.description);
            Token.setText(ApiApitoken.token);
            ExpiresAt.setText(ApiApitoken.expires_at.toString());
            RefreshToken.setText(ApiApitoken.refresh_token);

            EntApitoken dbEntApitoken = new EntApitoken();
            dbEntApitoken.setSyncId(ApiApitoken.id);
            dbEntApitoken.setDescription(ApiApitoken.description);
            dbEntApitoken.setToken(ApiApitoken.token);
            dbEntApitoken.setExpiresAt(ApiApitoken.expires_at);
            dbEntApitoken.setRefreshToken(ApiApitoken.refresh_token);
            dbEntApitoken.save();

            mApiApitoken = ApiApitoken;
        }
    }

    public class DeleteApiTokenTask extends AsyncTask<ApiApitoken, Void, Void> {

        @Override
        protected Void doInBackground(ApiApitoken... params) {
            try {
                ApiApitoken.delete(params[0]);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        public void execute(String description) {
        }
    }

    public class ListClientsTask extends AsyncTask<String, Void, ApiClient> {

        @Override
        protected ApiClient doInBackground(String... params) {
            try {
                return ApiClient.list(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(ApiClient ApiClient) {
            EntClient dbEntClient = new EntClient();
            dbEntClient.setSyncId(ApiClient.id);
            dbEntClient.setExternalId(ApiClient.external_id);
            dbEntClient.setSearchCode(ApiClient.search_code);
            dbEntClient.setCompanyName(ApiClient.company_name);
            dbEntClient.setPhoneNumber(ApiClient.phone_number);
            dbEntClient.setFaxNumber(ApiClient.fax_number);
            dbEntClient.setEmailAddress(ApiClient.email_address);
            dbEntClient.setArchived(ApiClient.archived);
            dbEntClient.setUpdatedAt(ApiClient.updated_at);
            dbEntClient.setUrl(ApiClient.url);
            dbEntClient.setAddressesId(ApiClient.address_id);
            dbEntClient.setAddressesType(ApiClient.address_type);
            dbEntClient.setAddressesLine1(ApiClient.address_line1);
            dbEntClient.setAddressesPostalCode(ApiClient.address_postal_code);
            dbEntClient.setAddressesCity(ApiClient.address_city);
            dbEntClient.setAddressesCountry(ApiClient.address_country);
            dbEntClient.setAddressesUpdatedAt(ApiClient.address_updated_at);
            dbEntClient.save();
        }
    }

    public class GetClientsTask extends AsyncTask<String, Void, ApiClient> {

        @Override
        protected ApiClient doInBackground(String... params) {
            try {
                return ApiClient.get(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public class ListClientlocationsTask extends AsyncTask<String, Void, ApiClientLocation> {

        @Override
        protected ApiClientLocation doInBackground(String... params) {
            try {
                return ApiClientLocation.list(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(ApiClientLocation ApiClientLocation) {
            EntClientLocation dbEntClientLocation = new EntClientLocation();
            dbEntClientLocation.setClientId(ApiClientLocation.client_id);
            dbEntClientLocation.setExternalId(ApiClientLocation.external_id);
            dbEntClientLocation.setName(ApiClientLocation.name);
            dbEntClientLocation.setPhoneNumber(ApiClientLocation.phone_number);
            dbEntClientLocation.setEmailAddress(ApiClientLocation.email_address);
            dbEntClientLocation.setArchived(ApiClientLocation.archived);
            dbEntClientLocation.setUpdatedAt(ApiClientLocation.updated_at);
            dbEntClientLocation.setUrl(ApiClientLocation.url);
            dbEntClientLocation.setClientId(ApiClientLocation.client_id);
            dbEntClientLocation.setClientUpdatedAt(ApiClientLocation.client_updated_at);
            dbEntClientLocation.setClientUrl(ApiClientLocation.client_url);
            dbEntClientLocation.setAddressesId(ApiClientLocation.addresses_id);
            dbEntClientLocation.setAddressesType(ApiClientLocation.addresses_type);
            dbEntClientLocation.setAddressesLine1(ApiClientLocation.addresses_line1);
            dbEntClientLocation.setAddressesPostalCode(ApiClientLocation.addresses_postal_code);
            dbEntClientLocation.setAddressesCity(ApiClientLocation.addresses_city);
            dbEntClientLocation.setAddressesCountry(ApiClientLocation.addresses_country);
            dbEntClientLocation.setAddressesUpdatedAt(ApiClientLocation.addresses_updated_at);
            dbEntClientLocation.save();
        }
    }

    public class GetClientlocationsTask extends AsyncTask<String, Void, ApiClientLocation> {

        @Override
        protected ApiClientLocation doInBackground(String... params) {
            try {
                return ApiClientLocation.get(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public class ListWarehousesTask extends AsyncTask<String, Void, ApiWarehouse> {

        @Override
        protected ApiWarehouse doInBackground(String... params) {
            try {
                return ApiWarehouse.list(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(ApiWarehouse ApiWarehouse) {
            EntWarehouse dbEntWarehouse = new EntWarehouse();
            dbEntWarehouse.setSyncId(ApiWarehouse.id);
            dbEntWarehouse.setExternalId(ApiWarehouse.external_id);
            dbEntWarehouse.setName(ApiWarehouse.name);
            dbEntWarehouse.setLength(ApiWarehouse.length);
            dbEntWarehouse.setWidth(ApiWarehouse.width);
            dbEntWarehouse.setHeight(ApiWarehouse.height);
            dbEntWarehouse.setRefrigerated(ApiWarehouse.refrigerated);
            dbEntWarehouse.setTemperature(ApiWarehouse.temperature);
            dbEntWarehouse.setSprinklers(ApiWarehouse.sprinklers);
            dbEntWarehouse.setHazardousSubstances(ApiWarehouse.hazardous_substances);
            dbEntWarehouse.setImperviousFloor(ApiWarehouse.impervious_floor);
            dbEntWarehouse.setFireAlarm(ApiWarehouse.fire_alarm);
            dbEntWarehouse.setFloorHeating(ApiWarehouse.floor_heating);
            dbEntWarehouse.setFloorHeatingDepth(ApiWarehouse.floor_heating_depth);
            dbEntWarehouse.setInspectionFrequency(ApiWarehouse.inspection_frequency);
            dbEntWarehouse.setArchived(ApiWarehouse.archived);
            dbEntWarehouse.setUpdatedAt(ApiWarehouse.updated_at);
            dbEntWarehouse.setUrl(ApiWarehouse.url);
            dbEntWarehouse.setSurface(ApiWarehouse.surface);
            dbEntWarehouse.setClientLocation(ApiWarehouse.client_location);
            dbEntWarehouse.save();
        }
    }

    public class GetWarehousesTask extends AsyncTask<String, Void, ApiWarehouse> {

        @Override
        protected ApiWarehouse doInBackground(String... params) {
            try {
                return ApiWarehouse.get(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public class ListContactsTask extends AsyncTask<String, Void, ApiContact> {

        @Override
        protected ApiContact doInBackground(String... params) {
            try {
                return ApiContact.list(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(ApiContact ApiContact) {
            EntContact dbEntContact = new EntContact();
            dbEntContact.setSyncId(ApiContact.id);
            dbEntContact.setExternalId(ApiContact.external_id);
            dbEntContact.setName(ApiContact.name);
            dbEntContact.setPhoneNumber(ApiContact.phone_number);
            dbEntContact.setMobileNumber(ApiContact.mobile_number);
            dbEntContact.setEmailAddress(ApiContact.email_address);
            dbEntContact.setUpdatedAt(ApiContact.updated_at);
            dbEntContact.setUrl(ApiContact.url);
            dbEntContact.setClient(ApiContact.client);
            dbEntContact.setClientLocation(ApiContact.client_location_id);
            dbEntContact.save();
        }
    }

    public class GetContactsTask extends AsyncTask<String, Void, ApiContact> {

        @Override
        protected ApiContact doInBackground(String... params) {
            try {
                return ApiContact.get(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    public class ListAssignmentsTask extends AsyncTask<String, Void, ApiAssignment> {

        @Override
        protected ApiAssignment doInBackground(String... params) {
            try {
                return ApiAssignment.list(params[0]);
            } catch (JSONException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        protected void onPostExecute(ApiAssignment ApiAssignment) {
            EntAssignment dbEntAssignment = new EntAssignment();
            dbEntAssignment.setSyncId(ApiAssignment.id);
            dbEntAssignment.setExternalId(ApiAssignment.external_id);
            dbEntAssignment.setType(ApiAssignment.type);
            dbEntAssignment.setDate(ApiAssignment.date);
            dbEntAssignment.setRemarks(ApiAssignment.remarks);
            dbEntAssignment.setArchived(ApiAssignment.archived);
            dbEntAssignment.setUpdatedAt(ApiAssignment.updated_at);
            dbEntAssignment.setUrl(ApiAssignment.url);
            dbEntAssignment.setClientLocationId(ApiAssignment.client_location_id);
            dbEntAssignment.setClientLocationUpdatedAt(ApiAssignment.client_location_updated_at);
            dbEntAssignment.setClientLocationUrl(ApiAssignment.client_location_url);
            dbEntAssignment.setArchived(ApiAssignment.archived);
            dbEntAssignment.setUpdatedAt(ApiAssignment.updated_at);
            dbEntAssignment.setUrl(ApiAssignment.url);
            dbEntAssignment.setWarehousesId(ApiAssignment.warehouses_id);
            dbEntAssignment.setWarehousesUpdatedAt(ApiAssignment.warehouses_updated_at);
            dbEntAssignment.setWarehousesUrl(ApiAssignment.warehouses_url);
            dbEntAssignment.setEmployeesId(ApiAssignment.employees_id);
            dbEntAssignment.setEmployeesUpdatedAt(ApiAssignment.employees_updated_at);
            dbEntAssignment.setEmployeesUrl(ApiAssignment.employees_url);
            dbEntAssignment.setStatusesId(ApiAssignment.statuses_id);
            dbEntAssignment.setStatusesStatus(ApiAssignment.statuses_status);
            dbEntAssignment.setStatusesCreatedAt(ApiAssignment.statuses_created_at);
            dbEntAssignment.setStatusesUpdatedAt(ApiAssignment.statuses_updated_at);
            dbEntAssignment.setStatusesUrl(ApiAssignment.statuses_url);
            dbEntAssignment.save();
        }

        public class GetAssignmentTask extends AsyncTask<String, Void, ApiAssignment> {

            @Override
            protected ApiAssignment doInBackground(String... params) {
                try {
                    return ApiAssignment.get(params[0]);
                } catch (JSONException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }
        }

    }
}

logcat(错误):

02-19 13:58:18144 7472-7472/nl.empoly.android。安全支持E/AndroidRuntime﹕ 致命异常:主进程:nl.empoly.android。安全支持,PID:7472 java.lang.NullPointerException,位于nl.empoly.android.safetysupport.ApiTokenActivity$CreateApiTokenTask.onPostExecute(APiTokenCactivity.java:98),位于nl.empoly.android.savetysuport.ApiTokenActivity$CreateApiPiToken Task.onpostExecutive(ApiToKen活动.java:76),位于android.os.AsyncTask.finish(AsyncTask.java:632),位于android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645),位于android.app.ActivityThread.main(ActivityThread.java:5748),位于java.lang.reflect.Method,android.pos.Looper.loop(Looper.java:146)。在dalvik.system.NativeStart的com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)上的java.lang.reflect.Method.invoke(本机方法)(方法.java:515)上的invokeNative(本机法)。main(本地方法

第98行代码错误:id . settext(apiapitoken . id);

第76行的代码错误:
公共类CreateApiToken任务扩展了Async任务{

有人能帮我吗?我还是个新手程序员:(

任何帮助都将不胜感激…

很抱歉没有具体说明代码:(

基本上,当我在Android Studio中运行我的应用程序以及在我的应用程序执行期间,该应用程序运行良好。但是当我输入描述字段(例如test6)然后按“创建”按钮时,应用程序崩溃了!我得到以下结果。

共有1个答案

郭元明
2023-03-14

我认为ID只是空的,你在上面调用setText()。在那里放一个断点并确保。

如果是这种情况,问题可能在其他地方,如果您需要帮助,请apitoken_activity.xml

 类似资料:
  • 我正在使用 设备:荣誉50,魔法用户界面4.2,Android版本11。 以下是崩溃日志: JAVAlang.SecurityException:GetNetworkTypeforSubscriber5在android上。操作系统。包裹android上的createExceptionOrNull(packet.java:2384)6。操作系统。包裹android上的createException(

  • 自定义datePicker代码: 这就是我如何在我的主要活动中使用这个类: Logcat:

  • 问题内容: 当我尝试访问Flask应用程序时,该应用程序崩溃了。 这类似于this或this。但是,我的设置似乎正确。 flask.cli.NoAppException:提供的文件/路径(服务器)似乎不存在。请确认路径正确。如果应用不在PYTHONPATH上,请确保扩展名为.py 我的环境变量设置正确。 我的服务器文件是y目录中没有任何文件。 我不记得对代码进行任何特殊更改。该错误可能来自哪里?

  • 在以前的代码上,谁医生帮了我 现在,android应用程序在我的手机上运行时崩溃了,这是错误日志 第一个问题是在我用相机扫描二维码后,它不能显示在二维码的结果进入 第二个问题是,我从存储器中选择了一个QRcode图像,然后点击确认,它崩溃了 下面是我认为的问题 类型不匹配:推断的类型是Uri?但乌里是意料之中的 冗余SAM构造函数 'onRequestPermissionsResult(Int,数

  • 把我的城市飞艇升级到7.2。没有编译错误和应用程序运行良好,直到它收到一个推送消息。此时,它将崩溃,出现以下堆栈跟踪: 当我检查类是否可见(Cmd-O)并开始键入时,类立即出现。 有人遇到过这个吗?我不知道怎么修好它。多谢了。