I have created an android application using Android Studio IDE while clicking the button in my app it does'nt navigate it to the another activity instead its throwing up the exception
Here is My Logcat:
02-10 11:33:56.030 7404-7404/com.example.mcs.oodoeg E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
at android.view.View.performClick(View.java:4275)
at android.view.View$PerformClick.run(View.java:17434)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ExceptionInInitializerError
at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
at android.view.View.performClick(View.java:4275)
at android.view.View$PerformClick.run(View.java:17434)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org.apache.ws.commons.serialize.DOMSerializer
at org.apache.xmlrpc.serializer.NodeSerializer.<clinit>(NodeSerializer.java:30)
at org.apache.xmlrpc.common.TypeFactoryImpl.<clinit>(TypeFactoryImpl.java:88)
at org.apache.xmlrpc.common.XmlRpcController.<init>(XmlRpcController.java:31)
at org.apache.xmlrpc.client.XmlRpcClient.<init>(XmlRpcClient.java:51)
at com.example.mcs.oodoeg.MainActivity.getXmlRpcClient(MainActivity.java:138)
at com.example.mcs.oodoeg.MainActivity.registerUser(MainActivity.java:103)
at com.example.mcs.oodoeg.MainActivity$1.onClick(MainActivity.java:45)
at android.view.View.performClick(View.java:4275)
at android.view.View$PerformClick.run(View.java:17434)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:177)
at android.app.ActivityThread.main(ActivityThread.java:4947)
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:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
This is my Main Activity class i have created two buttons here called register and signin:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn;
btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intObj = new Intent(MainActivity.this,MainActivity2.class);
startActivity(intObj);
}
});
Button btn2;
btn2=(Button) findViewById(R.id.button2);
btn2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent= new Intent(MainActivity.this,Sigin.class);
startActivity(intent);
}
} );
}
When the register button is clicked this Main Activity2 should be called:
public class MainActivity2 extends Activity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.next);
}
When sigin button is clicked this sigin class should be called:
public class Sigin extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sigin);
}
}
I think you are missing ws-commons-util-1.0.2.jar from $EXIST_HOME/lib/core.
You have to make sure you have included at least all of the libraries from $EXIST_HOME/lib/core.
Related
I'm trying to make my class Parcelable, but I keep getting these errors:
08-28 07:42:55.598 7810-7810/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3617)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = thesleeplesselite.drgreenthumb.CropRotationPlan$SubPlan)
at android.os.Parcel.writeSerializable(Parcel.java:1279)
at android.os.Parcel.writeValue(Parcel.java:1233)
at android.os.Parcel.writeList(Parcel.java:622)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:248)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6850)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
at android.app.Activity.startActivityForResult(Activity.java:3388)
at android.app.Activity.startActivityForResult(Activity.java:3349)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.io.NotSerializableException: thesleeplesselite.drgreenthumb.CropRotationPlan
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1364)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:979)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:368)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1074)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at android.os.Parcel.writeSerializable(Parcel.java:1274)
at android.os.Parcel.writeValue(Parcel.java:1233)
at android.os.Parcel.writeList(Parcel.java:622)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:248)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6850)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
at android.app.Activity.startActivityForResult(Activity.java:3388)
at android.app.Activity.startActivityForResult(Activity.java:3349)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Here's the structure of my class; it has an inner class. I don't think it's ideal to put my entire code. It's just too long.
public class CropRotationPlan implements Parcelable {
String name; // Name of plan
HashMap<String, List<HashMap<String, String>>> listOfFamilies; // HashMap containing Plant Family Names as keys and a List of plants
List<SubPlan> listOfSubPlans;
public CropRotationPlan() {
name = null;
listOfFamilies = new HashMap<>();
listOfSubPlans = new ArrayList<>();
}
...
#Override
public int describeContents() {
return 0;
}
#Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.name);
dest.writeSerializable(this.listOfFamilies);
dest.writeList(this.listOfSubPlans);
}
protected CropRotationPlan(Parcel in) {
this.name = in.readString();
this.listOfFamilies = (HashMap<String, List<HashMap<String, String>>>) in.readSerializable();
this.listOfSubPlans = new ArrayList<SubPlan>();
in.readList(this.listOfSubPlans, List.class.getClassLoader());
}
public static final Parcelable.Creator<CropRotationPlan> CREATOR = new Parcelable.Creator<CropRotationPlan>() {
public CropRotationPlan createFromParcel(Parcel source) {
return new CropRotationPlan(source);
}
public CropRotationPlan[] newArray(int size) {
return new CropRotationPlan[size];
}
};
public class SubPlan implements Serializable {
int year;
HashMap<String, Integer> orderOfFamilies;
...
}
}
At this point, I seriously have no idea what to do.
CropRotationPlan.java:248 is dest.writeList(this.listOfSubPlans); in writeToParcel()
Also, in another class, I have this method:
public void btnViewPlan(View view) {
// We'll be sending our cropRotationPlan object to next activity (PlanActivity)
// And we'll be expecting a result (since we'll allow the user to manipulate the object there)
Intent i = new Intent(CropRotationPlannerActivity.this, PlanActivity.class);
i.putExtra("cropRotationPlan", cropRotationPlan);
startActivityForResult(i, SET_PLAN_REQUEST);
}
CropRotationPlannerActivity.java:197 is: startActivityForResult(i, SET_PLAN_REQUEST);
I've tried placing my inner class into a separate class, and then had it to implement Serializable OR Parcelable (just one of 'em) but I just keep getting errors. All relating to my SubPlan class; like problems with marshing it and stuff. Along with using TypedList instead somewhere in the code.
Help would be appreciated. Thanks!
I just don't know what to do anymore.
PS: I'm sorry if I sound so incoherent right now. I might edit this post once I recover my sanity.
CODE FOR SubPlan CLASS
public class SubPlan implements Serializable {
int year;
HashMap<String, Integer> orderOfFamilies;
public SubPlan(int year) {
orderOfFamilies = new HashMap<>();
this.year = year;
int temp = -1;
for (String key : listOfFamilies.keySet()) {
orderOfFamilies.put(key, ++temp);
}
}
public SubPlan(int year, HashMap<String, Integer> orderOfFamilies) {
this.year = year;
this.orderOfFamilies = orderOfFamilies;
}
public int getYear() {
return year;
}
public String getName() {
return "Year " + year;
}
public String getKey(int index) {
for (String key : orderOfFamilies.keySet()) {
if (orderOfFamilies.get(key).equals(index))
return key;
}
return null;
}
public int getLocationOf(String family) {
return orderOfFamilies.get(family);
}
public void setOrderOfFamily(String family, int index) {
if (orderOfFamilies.containsKey(family))
orderOfFamilies.put(family, index);
}
public void removeFamily(String family) {
if (orderOfFamilies.containsKey(family)) {
orderOfFamilies.remove(family);
}
}
public void rotateFamilies() {
for (int i = 0; i < getNumberOfFamilies(); i++) {
String family = getKey(i);
// if not last family on list
if (orderOfFamilies.get(family) != getNumberOfFamilies() - 1)
setOrderOfFamily(family, i + 1);
else
setOrderOfFamily(family, 0);
}
}
}
Additionally, getNumberOfFamilies() is a method belonging to the parent class, with the following definition:
public int getNumberOfFamilies() {
return listOfFamilies.size();
}
I have initially not let SubPlan implement Serializable and these are the exceptions I get:
08-28 08:31:07.809 8741-8741/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3617)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Parcel: unable to marshal value thesleeplesselite.drgreenthumb.CropRotationPlan$SubPlan#4191f010
at android.os.Parcel.writeValue(Parcel.java:1235)
at android.os.Parcel.writeList(Parcel.java:622)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:249)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at android.os.Parcel.writeValue(Parcel.java:1173)
at android.os.Parcel.writeMapInternal(Parcel.java:591)
at android.os.Bundle.writeToParcel(Bundle.java:1627)
at android.os.Parcel.writeBundle(Parcel.java:605)
at android.content.Intent.writeToParcel(Intent.java:6850)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1908)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1483)
at android.app.Activity.startActivityForResult(Activity.java:3388)
at android.app.Activity.startActivityForResult(Activity.java:3349)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:820)
at thesleeplesselite.drgreenthumb.CropRotationPlannerActivity.btnViewPlan(CropRotationPlannerActivity.java:197)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
08-28 08:31:09.543 531-1643/? E/InputDispatcher﹕ channel '41d34990 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
08-28 08:31:09.543 531-1643/? E/InputDispatcher﹕ channel '4281f970 thesleeplesselite.drgreenthumb/thesleeplesselite.drgreenthumb.CropRotationPlannerActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
Additionally, I have tried implementing Parcelable on SubPlan and made it have its own class:
08-28 08:54:59.291 9245-9245/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3617)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at android.view.View$1.onClick(View.java:3612)
at android.view.View.performClick(View.java:4222)
at android.view.View$PerformClick.run(View.java:17620)
at android.os.Handler.handleCallback(Handler.java:800)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5391)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.StackOverflowError
at java.io.SerializationHandleMap.get(SerializationHandleMap.java:63)
at java.io.ObjectOutputStream.dumpCycle(ObjectOutputStream.java:425)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1566)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.util.HashMap.writeObject(HashMap.java:1015)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.util.ArrayList.writeObject(ArrayList.java:644)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at java.util.HashMap.writeObject(HashMap.java:1016)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1053)
at java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1404)
at java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1671)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1517)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1481)
at android.os.Parcel.writeSerializable(Parcel.java:1274)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:185)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
at android.os.Parcel.writeTypedList(Parcel.java:1017)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:186)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
at android.os.Parcel.writeTypedList(Parcel.java:1017)
at thesleeplesselite.drgreenthumb.CropRotationPlan.writeToParcel(CropRotationPlan.java:186)
at android.os.Parcel.writeParcelable(Parcel.java:1254)
at thesleeplesselite.drgreenthumb.SubPlan.writeToParcel(SubPlan.java:83)
at android.os.Parcel.writeTypedList(Parcel.java:1017)
at thesleeplesselite.drgreenthumb.CropRotationPlan.write
The root cause is listed at the bottom, and the error says it all:
java.io.NotSerializableException: thesleeplesselite.drgreenthumb.CropRotationPlan
The class CropRotationPlan must be Serializable.
Update
Because SubPlan is not static, serializing SubPlan also means serializing the outer class CropRotationPlan. Since only the SubPlan constructor seems to use the outer class, change the class to static and send listOfFamilies in as a parameter on the constructor.
I have a problem. I want to read value Integer of activity "Settings" in the service GPSTracker and use it there. I use this SharedPrefrences and confirming key input. If the data is validated that the application returns to class FullscreenActivity.
This is the code responsible for this in activity Settings:
SharedPreferences.Editor editor;
public static final String NAME = "DISTANCE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
final View controlsView = findViewById(R.id.fullscreen_content_controls);
final View contentView = findViewById(R.id.fullscreen_content);
SharedPreferences pref = getApplicationContext().getSharedPreferences(NAME, MODE_PRIVATE);
editor=pref.edit();
Edit1= (EditText) findViewById(R.id.editSkan);
accept= (Button) findViewById(R.id.buttonSkan);
accept.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
if (!Edit1.getText().toString().equals(""))
value = Integer.parseInt(Edit1.getText().toString());
editor.putInt("settings", value);
editor.commit();
Toast.makeText(getApplicationContext(), "Changed, value + " m", Toast.LENGTH_SHORT).show();
finish();
}
});
A code in GPSTracker like this:
SharedPreferences pref;
(...)
private int downloadSettings()
{
pref=context.getSharedPreferences("DISTANCE", Activity.MODE_PRIVATE);
value = pref.getInt("settings",15);
return value;
}
and a method call:
int dist = downloadSettings();
When I run the apps I get two errors in the log:
*java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adam.mobileproject/com.example.adam.mobileproject.FullscreenActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.adam.mobileproject.GPSTracker.downloadSettings(GPSTracker.java:284)
at com.example.adam.mobileproject.GPSTracker.<init>(GPSTracker.java:200)
at com.example.adam.mobileproject.FullscreenActivity.onCreate(FullscreenActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)*
PLEASE HELP!!!
The problem is definitely that context is null.
However, just like the Activity class, the Service class extends Context, so you should be able to replace context with this or getApplicationContext().
Try this:
private int downloadSettings()
{
pref = getApplicationContext().getSharedPreferences("DISTANCE", Activity.MODE_PRIVATE);
value = pref.getInt("settings",15);
return value;
}
I have created a custom View which draws a line:
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
#Override
public void onDraw(Canvas canvas) {
canvas.drawLine(0, 0, 100, 100, paint);
}
}
I have a MainActivity class and activity_main layout where my layout contains an image and several buttons. I want to put the custom view that I created to my XML file(activity_main) where a line would be drawn on top of the image.
I tried adding it:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
//imageview and buttons here
<com.myapp.alphasickbro.myapplication2.DrawView
android:id="#+id/paintView"
android:layout_width="100dp"
android:layout_height="100dp"
/>
</RelativeLayout>
Here is my MainActivity:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
But when I run it, the app unfortunately stops. Did I miss something? What lines of code should I add?
Any answer would be appreciated
EDIT:
04-18 15:24:47.517 26732-26732/com.myapp.alphasickbro.myapplication2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myapp.alphasickbro.myapplication2, PID: 26732
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.alphasickbro.myapplication2/com.myapp.alphasickbro.myapplication2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class com.myapp.alphasickbro.myapplication2.DrawView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.myapp.alphasickbro.myapplication2.DrawView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:2002)
at com.myapp.alphasickbro.myapplication2.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:2002)
at com.myapp.alphasickbro.myapplication2.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.myapp.alphasickbro.myapplication2.DrawView.<init>(DrawView.java:27)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:2002)
at com.myapp.alphasickbro.myapplication2.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5411)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5268)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
I think you need to add the missing constructors. Clean your project.
public class DrawView extends View {
Paint paint;
public DrawView(Context context) {
super(context);
init();
}
public DrawView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public DrawView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
paint = new Paint();
paint.setColor(Color.BLACK);
}
}
I feel bad for asking about this but for 2 hours now I can't find any way to solve this:
**The Problem: ** I have set up a canvas area(where i plot a drawable figure) and a button below the canvas area.
In my AnimatedView class I want find the button and give it an onClickListener, but it returns a NullPointerException.
my activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#000000">
<com.example.julle.bounce.AnimatedView
android:id="#+id/anim_view"
android:layout_height="300dp"
android:layout_width="fill_parent"/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/anim_view"
android:id="#+id/button_jump"
android:clickable="true"
android:text="Jump"/>
my code for AnimatedView.java:
package com.example.julle.bounce;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class AnimatedView extends ImageView{
private Context mContext;
int x = -1;
int y = -1;
private int xVelocity = 10;
private int yVelocity = 5;
private Handler h;
private final int FRAME_RATE = 30;
boolean jump=false;
public AnimatedView(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
final Button button = (Button) findViewById(R.id.button_jump);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
jump=true;
}
});
h = new Handler();
}
private Runnable r = new Runnable() {
#Override
public void run() {
invalidate();
}
};
protected void onDraw(Canvas c) {
BitmapDrawable ball = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.ball);
if(jump==true) {
if (y < 0) {
y = this.getHeight() / 2;
} else {
y += yVelocity;
}
jump=false;
}else{
y= this.getHeight()/2;
}
c.drawBitmap(ball.getBitmap(), x, y, null);
h.postDelayed(r, FRAME_RATE);
}
}
and my MainActivity:
package com.example.julle.bounce;
import ...
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I believe I've realised the problem: the buttons are existent in the MainActivity class but not in my AnimatedView class. Allthou it might be very simple, I'm not sure how to solve that.
Thank you for all replies!
Sorry, totally forgot that I changed the code. AnimatedView is updated:
The line that gives NullPointException is line 26 in AnimatedView: button.setOnClickListener...
logcat:
02-24 14:47:32.005 31934-31934/com.example.julle.bounce E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.julle.bounce/com.example.julle.bounce.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class com.example.julle.bounce.AnimatedView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class com.example.julle.bounce.AnimatedView
at android.view.LayoutInflater.createView(LayoutInflater.java:613)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.julle.bounce.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.julle.bounce.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.julle.bounce.AnimatedView.<init>(AnimatedView.java:26)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:587)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.ActionBarActivityDelegateBase.setContentView(ActionBarActivityDelegateBase.java:228)
at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:102)
at com.example.julle.bounce.MainActivity.onCreate(MainActivity.java:23)
at android.app.Activity.performCreate(Activity.java:5206)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
at android.app.ActivityThread.access$700(ActivityThread.java:140)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
You can pass a reference to your button from main activity to AnimatedView class.
package com.example.julle.bounce;
import ...
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewByID(R.id.button_jump);
AnimatedView av = (AnimatedView)findViewByID(R.id.anm_view);
av.setJumpButton(btn);
}
}
You will need to add the setJumpButton method in your AnimatedView class.
When I test my app, after close app and clean memory(in my case, CleanMaster app) and then reopen it again, it force close. I try search for cause but can't find solvable solution.
It work all fine if not clean memory. I wonder if anything need to be saved and restore after these incident. I'm quite newby for Android.
here is log
06-29 11:59:19.479 22283-22283/com.thaifasttel D/WebView﹕ onTrimMemory: 20
06-29 11:59:33.985 22524-22524/com.thaifasttel D/jdwp﹕ sendBufferedRequest : len=0x39
06-29 11:59:33.993 22524-22524/com.thaifasttel W/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
06-29 11:59:34.050 22524-22524/com.thaifasttel D/dalvikvm﹕ newInstance failed: no <init>()
06-29 11:59:34.052 22524-22524/com.thaifasttel D/AndroidRuntime﹕ Shutting down VM
06-29 11:59:34.052 22524-22524/com.thaifasttel W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40d6f9a8)
06-29 11:59:34.060 22524-22524/com.thaifasttel E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.thaifasttel/com.thaifasttel.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.thaifasttel.MainActivity$PlaceholderFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.thaifasttel.MainActivity$PlaceholderFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.support.v4.app.Fragment.instantiate(Fragment.java:413)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1801)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:97)
at com.thaifasttel.MainActivity.onCreate(MainActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.thaifasttel.MainActivity$PlaceholderFragment; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.support.v4.app.Fragment.instantiate(Fragment.java:402)
at android.support.v4.app.FragmentState.instantiate(Fragment.java:97)
at android.support.v4.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1801)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:213)
at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:97)
at com.thaifasttel.MainActivity.onCreate(MainActivity.java:73)
at android.app.Activity.performCreate(Activity.java:5122)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
at android.app.ActivityThread.access$600(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
#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;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
return id == R.id.action_settings || super.onOptionsItemSelected(item);
}
public class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.e("My App", "onCreateView");
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
WebView myWebView;
RelativeLayout splash_view;
TextView splash_text;
SharedPreferences Usettings;
String lang="th";
int isloadwa=0;
AssetManager assetPath = getAssets();
String waAssetPath ="web";
String wabase=getApplicationContext().getFilesDir().getPath();
String waIntPath = "web";
String waIntPath2 = wabase+"/"+waIntPath;
String baseupdatefolder="http://www.test.com/test/webapp";
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.e("My App", "onActivityCreated");
myWebView = (WebView) getView().findViewById(R.id.webview);
splash_view = (RelativeLayout) getView().findViewById(R.id.splashview);
splash_text = (TextView) getView().findViewById(R.id.splash_status);
inituserPref();
copydir();
}
#Override
public void onStart(){
super.onStart();
Log.e("My App", "onstart");
}
#Override
public void onResume(){
super.onResume();
Log.e("My App", "onResume");
if(isloadwa==1) {
if (isConnected()) {
Log.e("My App", "check update in app");
splash_text.setText(a_check_update);
checkupdate();
}
}
}
// do a lot of method after this