저는 안드로이드 세계에서 멍청이이고, 운동을위한 애완 동물 프로젝트를하고 있습니다. 그것은 단지 두 가지 활동이있는 매우 간단한 알림 같은 앱입니다. 하나는 맞춤형 ListView로 기존 알람을 표시합니다. 다른 버튼을 시작하기위한 몇 가지 버튼이 있는데 이는 알람 추가/편집을위한 것입니다. 이전 ListView 활동으로 이어지는 버튼이 있습니다.android.app.Application은 NullPointerException으로 인해 인스턴스화 될 수 없습니다.
내가 최근에 만난 이상한 상황이 있습니다. 내 응용 프로그램이 잘 작동합니다. 하지만 문제는 내가 추가/편집 활동을 트리거하고 ListView로 돌아가서 다시 실행 (또는 다시 설치한다고 말해야합니까?) 일 때입니다. 오류 메시지가 나타납니다. 그러나 그것은 단지 잠시 나타날 것이고 앱이 시작될 것입니다.
내가 로그에서 잡은 오류 메시지가 말한다 : 내 코드에서 잘못입니다
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application android.app.Application: java.lang.NullPointerException
at android.app.LoadedApk.makeApplication(LoadedApk.java:482)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3909)
at android.app.ActivityThread.access$1300(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4340)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.LoadedApk.initializeJavaContextClassLoader(LoadedApk.java:362)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:305)
at android.app.LoadedApk.makeApplication(LoadedApk.java:474)
... 11 more
그것은 명시 적으로 지적하지 않습니다. 그래서 나는 그것을 교정하는 방법에 대한 단서가 없습니다. 비슷한 문제가 발생 했습니까? 모든 제안을 주시면 감사하겠습니다!
다음는 추가/편집 활동의 코드입니다 :
매니페스트는 다음과 같이 간다public class EditEntry extends Activity
{
private AutoCompleteTextView foodNameTextView;
private DatePicker datePicker;
// store values in AutoCompleteTextView & DatePicker
private String foodName;
private Calendar foodDate;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.edit);
// dummy selections for AutoCompleteTextView
String[] foodList = new String[]{"meat", "fruit", "vega"};
// instantiate AutoCompleteTextView & DatePicker
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.food_list_dropdown, foodList);
foodNameTextView = (AutoCompleteTextView)findViewById(R.id.foodName);
foodNameTextView.setAdapter(arrayAdapter);
datePicker = (DatePicker)findViewById(R.id.date_picker);
// get intent from ReminderList.
Intent intent = getIntent();
// get extras from intent. Return null if intent is sent from "add" action.
foodName = intent.getStringExtra("foodName");
foodDate = (Calendar) intent.getSerializableExtra("foodDate");
// set default values for widgets if it is an "edit" action.
if (null != foodName)
{
foodNameTextView.setText(foodName);
datePicker.init(foodDate.get(Calendar.YEAR), foodDate.get(Calendar.MONTH), foodDate.get(Calendar.DAY_OF_MONTH),
new OnDateChangedListener()
{ // will implement date input check later.
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {}
});
}
// Submit will add/modify the data in xml file. Back will start ReminderList activity
Button submit = (Button)findViewById(R.id.entry_submit);
Button back = (Button)findViewById(R.id.entry_back);
submit.setOnClickListener(new SubmitButtonListener());
back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setClass(EditEntry.this, FoodReminderList.class);
startActivity(intent);
}
});
}
// add or modify data in xml file
@SuppressWarnings("unused")
class SubmitButtonListener implements OnClickListener
{
Calendar foodDate = Calendar.getInstance();
@Override
public void onClick(View v)
{
XmlUtil xmlUtil = new XmlUtil();
// determine if it is an "edit" action.
if (null != foodName)
{
FoodInfo foodInfo = new FoodInfo(foodName, foodDate);
// delete the old data entry
xmlUtil.deleteEntry(foodInfo);
// cancel old alarm
FoodReceiver alarm = new FoodReceiver(EditEntry.this, foodDate, false);
}
// get new input values
foodName = foodNameTextView.getText().toString();
foodDate.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth(), 0, 0, 0);
// update xml file
FoodInfo foodInfo = new FoodInfo(foodName, foodDate);
xmlUtil.updateEntry(foodInfo);
// set new alarm
FoodReceiver alarm = new FoodReceiver(EditEntry.this, foodDate, true);
// popup toast confirming the submit
Toast.makeText(EditEntry.this, "Reminder Added", Toast.LENGTH_SHORT).show();
// clear widgets
foodNameTextView.setText("");
Calendar currentDate = Calendar.getInstance();
datePicker.updateDate(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH));
}
}
}
:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ca.maxiao.Food"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".FoodReminderList" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:label="@string/app_name"
android:name=".EditEntry" >
</activity>
<activity
android:label='@string/app_name'
android:name=".FoodReminder"></activity>
<receiver android:name="ca.maxiao.Food.FoodReceiver">
<intent-filter>
<action android:name="Alarm_Setting" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>
유사한 오류에 대한 [게시물] (http://www.mail-archive.com/[email protected]/msg194903.html)이 있습니다. 스레드 레이스 문제 일 수 있지만 여전히 코드를 수정하는 방법을 모르는 것으로 알고 있습니다. – Selkie
여기에 매니페스트 파일을 추가 할 수 있습니까? – Yury
. 매니페스트가 추가되었습니다. – Selkie