Can anyone here help me getting ftp4j running in my app? I have written what should just connect then disconnect but it crashes the app. I have googled ALL OVER and can NOT figure out how to get it implemented. Any help appreciated.
EDIT: What I was REALLY asking for was what YOU would do to make it work, but I'll post my non functioning code I guess. FYI I did give permissions for internet.
Main.java:
package com.JKIC.pictures;
import java.io.IOException;
import it.sauronsoftware.ftp4j.FTPClient;
import it.sauronsoftware.ftp4j.FTPException;
import it.sauronsoftware.ftp4j.FTPIllegalReplyException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
public class Main extends Activity {
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
FTPClient ftp = new FTPClient();
ftp.connect("xxx.com);
ftp.login("xxx", "xxx");
ftp.disconnect(true);
} catch (IllegalStateException e) {
String test = e.toString();
TextView testview = (TextView) findViewById(R.id.textView1);
testview.setText(test);
} catch (IOException e) {
String test = e.toString();
TextView testview = (TextView) findViewById(R.id.textView1);
testview.setText(test);
} catch (FTPIllegalReplyException e) {
String test = e.toString();
TextView testview = (TextView) findViewById(R.id.textView1);
testview.setText(test);
} catch (FTPException e) {
String test = e.toString();
TextView testview = (TextView) findViewById(R.id.textView1);
testview.setText(test);
}
}
@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;
}
}
Logcat:
07-16 00:20:42.000: E/Trace(3518): error opening trace file: No such file or directory (2)
07-16 00:20:42.580: D/AndroidRuntime(3518): Shutting down VM
07-16 00:20:42.580: W/dalvikvm(3518): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
07-16 00:20:42.610: E/AndroidRuntime(3518): FATAL EXCEPTION: main
07-16 00:20:42.610: E/AndroidRuntime(3518): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.JKIC.pictures/com.JKIC.pictures.Main}: android.os.NetworkOnMainThreadException
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread.access$600(ActivityThread.java:141)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.os.Looper.loop(Looper.java:137)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread.main(ActivityThread.java:5041)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.lang.reflect.Method.invoke(Method.java:511)
07-16 00:20:42.610: E/AndroidRuntime(3518): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
07-16 00:20:42.610: E/AndroidRuntime(3518): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
07-16 00:20:42.610: E/AndroidRuntime(3518): at dalvik.system.NativeStart.main(Native Method)
07-16 00:20:42.610: E/AndroidRuntime(3518): Caused by: android.os.NetworkOnMainThreadException
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.net.InetAddress.getByName(InetAddress.java:289)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.net.InetSocketAddress.<init>(InetSocketAddress.java:105)
07-16 00:20:42.610: E/AndroidRuntime(3518): at java.net.InetSocketAddress.<init>(InetSocketAddress.java:90)
07-16 00:20:42.610: E/AndroidRuntime(3518): at it.sauronsoftware.ftp4j.FTPConnector.tcpConnectForCommunicationChannel(FTPConnector.java:208)
07-16 00:20:42.610: E/AndroidRuntime(3518): at it.sauronsoftware.ftp4j.connectors.DirectConnector.connectForCommunicationChannel(DirectConnector.java:39)
07-16 00:20:42.610: E/AndroidRuntime(3518): at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1036)
07-16 00:20:42.610: E/AndroidRuntime(3518): at it.sauronsoftware.ftp4j.FTPClient.connect(FTPClient.java:1003)
07-16 00:20:42.610: E/AndroidRuntime(3518): at com.JKIC.pictures.Main.onCreate(Main.java:22)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.Activity.performCreate(Activity.java:5104)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
07-16 00:20:42.610: E/AndroidRuntime(3518): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
07-16 00:20:42.610: E/AndroidRuntime(3518): ... 11 more
07-16 00:20:42.760: D/dalvikvm(3518): GC_CONCURRENT freed 234K, 12% free 2630K/2980K, paused 6ms+4ms, total 170ms
If you post your code and logcat we could help you a little better.
zalez said:
If you post your code and logcat we could help you a little better.
Click to expand...
Click to collapse
Edited first post. Thanks for the help.
The crash you are experiencing is because you are doing network stuff on the UI thread. You need to create a separate thread for the ftp part. I don't have a ftp server to try to connect to or I would write something up.
---------- Post added at 08:22 PM ---------- Previous post was at 08:17 PM ----------
This should help:
http://stackoverflow.com/questions/15163094/how-to-use-ftp4-j-to-download-a-file-from-my-server-in-android-app
Related
I'm creating a new FragmentPreference and then I want add a OnClickListener to an Preference:
My PreferenceFragment-Class:
Code:
public class PreferencesFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}
}
And my FragmentActivity:
Code:
public class SettingsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferencesFragment frag = new PreferencesFragment();
getFragmentManager().beginTransaction().replace(android.R.id.content, frag).commit();
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
OnPreferenceClickListener Pref_OnClickhandler = new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
And the error:
02-10 08:06:10.598: E/AndroidRuntime(1836): FATAL EXCEPTION: main
02-10 08:06:10.598: E/AndroidRuntime(1836): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.SettingsActivity}: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Handler.dispatchMessage(Handler.java:99)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.os.Looper.loop(Looper.java:137)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): at java.lang.reflect.Method.invoke(Method.java:511)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-10 08:06:10.598: E/AndroidRuntime(1836): at dalvik.system.NativeStart.main(Native Method)
02-10 08:06:10.598: E/AndroidRuntime(1836): Caused by: java.lang.NullPointerException
02-10 08:06:10.598: E/AndroidRuntime(1836): at com.test.SettingsActivity.onCreate(SettingsActivity.java:44)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Activity.performCreate(Activity.java:5104)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-10 08:06:10.598: E/AndroidRuntime(1836): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-10 08:06:10.598: E/AndroidRuntime(1836): ... 11 more
Click to expand...
Click to collapse
Why I get a NullPointerException? The Preference does exist...
Code:
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
What happens when you comment the line you think is offending? And which line are you commenting?
Please give a thanks if you think this post helped you!
Sent from my Nexus 4 using XDA Premium 4 Mobile App .
When I comment the lines
Code:
Preference deleteLocalDataPref = frag.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
my preferences are shown correctly.
OK, I changed some parts. This is what works for me:
Code:
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
PreferenceFragment preferenceFragment = (PreferenceFragment) getFragmentManager().findFragmentById(R.id.pref_frag_id);
Preference deleteLocalDataPref = preferenceFragment.findPreference("deleteLocalData");
deleteLocalDataPref.setOnPreferenceClickListener(Pref_OnClickhandler);
}
Preference.OnPreferenceClickListener Pref_OnClickhandler = new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
new DeleteSettings().execute();
return false;
}
};
}
/res/layout/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:name="com.example.app.PreferencesFragment"
android:id="@+id/pref_frag_id"/>
</FrameLayout>
(Replace the package name.)
/res/xml/settings.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:key="deleteLocalData"
android:summary="@string/pref_delete_local_data_summary"
android:title="@string/pref_delete_local_data" />
</PreferenceScreen>
I changed the way the Fragment is added. If you need to do it dynamically, have a look at a tutorial again and follow it closely.
You don't need to use a PreferenceActivity. The PreferenceFragment kind of replaced it. It is more flexible (it can be added to any kind of Activity) and the PreferenceActivity should only be used for apps which are supposed to work on Android versions below 3.0.
when I try to use ShowcaseView I get error
Code:
@override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final ImageButton saveButton = (ImageButton) view.findViewById(R.id.button_Save);
ViewTarget viewTarget = new ViewTarget(saveButton);
showcaseView = new ShowcaseView.Builder(getActivity())
.setTarget(viewTarget)
.setContentTitle("Reset Button")
.setContentText("This will erase all the data in the table except the line that in progress")
.build();
}
when I tried to do the same thing in my fragmentactivity and didn't work, but when I did the same thing but took a view that declared in the fragmentactivity and not in the fragment it worked.
Logcat:
Code:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:724)
at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
at android.graphics.Bitmap.createBitmap(Bitmap.java:670)
at com.github.amlcurran.showcaseview.ShowcaseView.updateBitmap(ShowcaseView.java:169)
at com.github.amlcurran.showcaseview.ShowcaseView.onGlobalLayout(ShowcaseView.java:343)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:839)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
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:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I understand what the error said but how can I fix it?
I am getting a NullPointerException after the build but once my phone tries to launch the app. I do not understand where the problem is. Im just learning to code and this app is simply supposed to make a toast pop up Long if the checkbox is clicked and short if it isnt.
Code:
package universaltruth.toastee;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
public CheckBox longToast = (CheckBox) findViewById(R.id.checkbox);
public EditText editText = (EditText) findViewById(R.id.toastText);
public int toastLength = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnlongToast();
}
public void addListenerOnlongToast(){
longToast.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if(((CheckBox) view).isChecked()){
toastLength = '1';
}
}
});
}
public void toastMessage(View view){
String message = editText.getText().toString();
Toast.makeText(getApplicationContext(),message, (toastLength == 0) ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG).show();
}
@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;
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
LogCat:
02-08 12:48:34.718 6684-6684/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 12:48:34.718 6684-6684/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 12:48:34.718 6684-6684/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 6684
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:19)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************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:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:50.672 9121-9121/universaltruth.toastee I/SELinux﹕ Function: selinux_android_load_priority , priority [3] , priority version is VE=SEPF_SM-N910F_4.4.4_A024
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> Normal User
02-08 13:00:50.672 9121-9121/universaltruth.toastee E/dalvikvm﹕ >>>>> universaltruth.toastee [ userId:0 | appId:10384 ]
02-08 13:00:50.682 9121-9121/universaltruth.toastee E/SELinux﹕ [DEBUG] get_category: variable seinfocat: default sensitivity: NULL, cateogry: NULL
02-08 13:00:50.682 9121-9121/universaltruth.toastee D/dalvikvm﹕ Late-enabling CheckJNI
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD checking this for 10384
02-08 13:00:50.682 9121-9121/universaltruth.toastee I/libpersona﹕ KNOX_SDCARD not a persona
02-08 13:00:50.752 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ in addTimaSignatureService
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/TimaKeyStoreProvider﹕ Cannot add TimaSignature Service, License check Failed
02-08 13:00:50.762 9121-9121/universaltruth.toastee D/ActivityThread﹕ Added TimaKesytore provider
02-08 13:00:50.922 9121-9121/universaltruth.toastee D/AndroidRuntime﹕ Shutting down VM
02-08 13:00:50.922 9121-9121/universaltruth.toastee W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x4191bda0)
02-08 13:00:50.922 9121-9121/universaltruth.toastee E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: universaltruth.toastee, PID: 9121
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{universaltruth.toastee/universaltruth.toastee.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2408)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5748)
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:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.Activity.findViewById(Activity.java:2014)
at universaltruth.toastee.MainActivity.<init>(MainActivity.java:16)
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1208)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2399)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2599)
************at android.app.ActivityThread.access$900(ActivityThread.java:174)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:146)
************at android.app.ActivityThread.main(ActivityThread.java:5748)
************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:1291)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
************at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
************at dalvik.system.NativeStart.main(Native Method)
02-08 13:00:55.232 9121-9121/universaltruth.toastee I/Process﹕ Sending signal. PID: 9121 SIG: 9
Forgive me if I am not posting this correctly. This is my first time. I am open to any and all feedback. Thank you.
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Masrepus said:
Your problem is that you initialize the longToast checkbox outside of a method. But findViewById only returns a result if called after a call to setContentView(...), which is done in onCreate. So: put your initialization code into onCreate, after setContentView and it will work fine
Click to expand...
Click to collapse
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
UniversalTruth said:
Hey Masrepus,
Thanks a bunch for answering me.
I have moved the initializations to the on create after the setContentView. I am still getting the null pointer exception. Do you have any further advice?
Click to expand...
Click to collapse
Can you edit the first post with the new code (and new logcat)?
Yes, grab a new log and post it on pastebin
Then link the log from here
My app keeps crashing when I try to start this activity. It is the Kit Kat easter egg. here is the code:
Code:
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Bon Appetit!",
Toast.LENGTH_LONG).show();
Intent dessert = new Intent("com.android.systemui.DessertCase");
startActivity(dessert);
}
here is the logcat:
04-06 22:57:26.607 31168-31168/com.jonanomisk.dessert E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.jonanomisk.dessert, PID: 31168
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4007)
at android.view.View.performClick(View.java:4756)
at android.view.View$PerformClick.run(View.java:19748)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4002)
************at android.view.View.performClick(View.java:4756)
************at android.view.View$PerformClick.run(View.java:19748)
************at android.os.Handler.handleCallback(Handler.java:739)
************at android.os.Handler.dispatchMessage(Handler.java:95)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5254)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.systemui.DessertCase }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1765)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1485)
at android.app.Activity.startActivityForResult(Activity.java:3736)
at android.app.Activity.startActivityForResult(Activity.java:3697)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
at android.app.Activity.startActivity(Activity.java:4007)
at android.app.Activity.startActivity(Activity.java:3975)
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at android.view.View$1.onClick(View.java:4002)
************at android.view.View.performClick(View.java:4756)
************at android.view.View$PerformClick.run(View.java:19748)
************at android.os.Handler.handleCallback(Handler.java:739)
************at android.os.Handler.dispatchMessage(Handler.java:95)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5254)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Click to expand...
Click to collapse
Thanks!
JonanomisK said:
My app keeps crashing when I try to start this activity. It is the Kit Kat easter egg. here is the code:
Code:
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Bon Appetit!",
Toast.LENGTH_LONG).show();
Intent dessert = new Intent("com.android.systemui.DessertCase");
startActivity(dessert);
}
here is the logcat:
Thanks!
Click to expand...
Click to collapse
Code:
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
Line 50 is causing the issues - not sure which line it is but I can see a problem in your intent line. Try the below code:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");
startActivity(intent);
Jonny said:
Code:
at com.jonanomisk.dessert.MainActivity.onClick(MainActivity.java:50)
Line 50 is causing the issues - not sure which line it is but I can see a problem in your intent line. Try the below code:
Code:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");
startActivity(intent);
Click to expand...
Click to collapse
Thanks man that worked great!
JonanomisK said:
Thanks man that worked great!
Click to expand...
Click to collapse
Hoped it would - your problem was that you need to pass a context to the intent - usually for starting activities within your own app you can use "this" as the context - so it would be:
Code:
new Intent(this, "SomeActivity.class");
But the package that the easter egg is under is com.android.systemui so that's what you have to set the class name using that as the context:
Code:
intent.setClassName("com.android.systemui", "com.android.systemui.DessertCase");
Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
logcat:
Code:
09-09 21:37:16.148 18137-18137/? D/dalvikvm﹕ Late-enabling CheckJNI
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 614: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:17.515 18137-18137/? I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
09-09 21:37:17.515 18137-18137/? W/dalvikvm﹕ VFY: unable to resolve virtual method 636: Landroid/content/res/TypedArray;.getType (I)I
09-09 21:37:17.515 18137-18137/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002
09-09 21:37:18.133 18137-18137/? D/GoogleAPIMsg﹕ Construcao do Client Google
09-09 21:37:18.164 18137-18137/? D/Manager﹕ Loading Geofences...
09-09 21:37:18.203 18137-18137/? D/AndroidRuntime﹕ Shutting down VM
09-09 21:37:18.203 18137-18137/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x419307c0)
09-09 21:37:18.234 18137-18137/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartlocation.wilcocsjrxxlxpto/com.smartlocation.wilcocsjrxxlxpto.HomeScreen}: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
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:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Unable to invoke no-args constructor for interface com.google.android.gms.location.Geofence. Register an InstanceCreator with Gson for this type may fix this problem.
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at com.google.gson.Gson.fromJson(Gson.java:724)
at com.google.gson.Gson.fromJson(Gson.java:696)
at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************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 com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.google.android.gms.location.Geofence; abstract class or interface
at sun.misc.Unsafe.allocateInstance(Native Method)
************at java.lang.reflect.Method.invokeNative(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:525)
************at com.google.gson.internal.UnsafeAllocator$1.newInstance(UnsafeAllocator.java:48)
************at com.google.gson.internal.ConstructorConstructor$12.construct(ConstructorConstructor.java:207)
************at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:186)
************at com.google.gson.Gson.fromJson(Gson.java:810)
************at com.google.gson.Gson.fromJson(Gson.java:775)
************at com.google.gson.Gson.fromJson(Gson.java:724)
************at com.google.gson.Gson.fromJson(Gson.java:696)
************at com.smartlocation.wilcocsjrxxlxpto.core.Manager.loadGeofences(Manager.java:203)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.load(HomeScreen.java:252)
************at com.smartlocation.wilcocsjrxxlxpto.HomeScreen.onCreate(HomeScreen.java:66)
************at android.app.Activity.performCreate(Activity.java:5133)
************at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
************at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
************at android.app.ActivityThread.access$600(ActivityThread.java:153)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
************at android.os.Handler.dispatchMessage(Handler.java:99)
************at android.os.Looper.loop(Looper.java:137)
************at android.app.ActivityThread.main(ActivityThread.java:5289)
************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:739)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
************at dalvik.system.NativeStart.main(Native Method)
09-09 21:37:18.648 18137-18137/? I/Process﹕ Sending signal. PID: 18137 SIG: 9
code:
Code:
public class Manager implements ResultCallback<Status>, LocationListener {
// Tag para fazer debug
protected static final String MAN = "Manager";
protected static final String SMS = "eventSMS";
protected static final String RING = "eventRing";
private Context mAppContext;
private GoogleApiClient mGoogleApiClient;
private LocationRequest mLocationRequest;
// Listas de Geofences
private TreeMap<String, Geofence> mGeofences;
private TreeMap<String, Event> mEvents;
private int mCounterActiveGeofences;
private PendingIntent mGeofencePendingIntent;
private Intent updateLocIntent;
/* Save */
private Gson gson;
private SharedPreferences prefs;
public Manager(Context context, GoogleApiClient googleApiClient){
mGeofences = new TreeMap<String, Geofence>();
mEvents = new TreeMap<String, Event>();
mGeofencePendingIntent = null;
mAppContext = context;
mGoogleApiClient = googleApiClient;
mCounterActiveGeofences = 0;
prefs = context.getSharedPreferences(Constants.Geofences, Context.MODE_PRIVATE);
gson = new Gson();
}
...
public void saveGeofences(){
String json;
Geofence geofence;
SharedPreferences.Editor editor = prefs.edit();
Log.d(MAN, "Saving Geofences...");
for (Map.Entry<String, Geofence> entry : mGeofences.entrySet()) {
geofence = mGeofences.get(entry.getKey());
json = gson.toJson(geofence);
editor.putString(geofence.getRequestId(), json);
Log.d(MAN, geofence.getRequestId() + " json: " + json);
}
editor.apply();
}
public void loadGeofences(){
Map<String, ?> keys = prefs.getAll();
Log.d(MAN, "Loading Geofences...");
for (Map.Entry<String, ?> entry : keys.entrySet()) {
String jsonString = prefs.getString(entry.getKey(), null);
Geofence geofence = gson.fromJson(jsonString, Geofence.class);
Log.d(MAN, geofence.getRequestId());
mGeofences.put(geofence.getRequestId(), geofence);
}
}
}
Thank you in advance.
wilcocsjr said:
Hey guys,
I'm having a problem figuring out a way to store the geofences that my app creates, in order to load them when I run the app again. The purpose is to show a list of geofences created by the user.
I tried to serialize them using Java's Serialization and I also tried to use Gson to convert them into a Json string. The problem with Gson it's when I try to load them, it gives me an error message saying that Geofence is not a class. (which is true, it's an interface).
Thank you in advance.
Click to expand...
Click to collapse
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
AndroidFire said:
Could you show your code and show logcat read sticky thread how to post development questions
Sent from my SM-G530H using XDA Free mobile app
Click to expand...
Click to collapse
Just edited the original post, sorry about that