Issue:

I have a FragmentActivity called HomeFragment which has a Drawer with a ListView thats items take the user to other Fragments and Activities. When I click on an item that's supposed to take me to another Fragment, it works perfectly... but if I click on the one item (case MY_LOANS) that's supposed to take me to a different Activity, the application crashes with a NullPointerException in onSaveInstanceState.

I didn't know which part of my HomeActivity to specifically include because I'm not sure where the error is. However, the most relevant part I think is displayView() under the MY_LOANS case statement, where I call startActivity(). onSaveInstanceState() is also relevant because I get the null pointer there. The exact logcat error is below the code.

Another observation:

The app only crashes (with the whole Unfortunately... dialog) AFTER navigating to the MyLoans activity, which is weird I think.

Possible Duplicate? :

I should mention that the problem I have seems to be EXACTLY the same as in this SO question. However, the solution mentioned in the accepted answer does not work for me because my support libraries are up to date.

Also, the nullpointer in my question is on fragment, and NOT on the Bundle.

Code:

@SuppressLint("NewApi")
public class HomeActivity extends FragmentActivity {

public final static String FRAGMENT_TAG = "HomeActivity Fragment";

public final static int 
HOME = 0,
MY_LOANS = 1,
PENDING_REQ = 2,
BUSINESS_PROFILE = 3,
OWNERSHIP = 4,
PROFILE = 5,
NOTIF = 6,
LOGOUT = 7;

private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
private CharSequence mTitle;

// slide menu objects
private String[] mNavMenuTitles;
private TypedArray mNavMenuIcons;
private ArrayList<NavDrawerItem> mNavDrawerItems;
private NavDrawerListAdapter mAdapter;

//To manage user session
private SessionManager mManager;

//To manage fragments
private FragmentManager mFragManager;

private Fragment fragment;

private class SlideMenuClickListener implements ListView.OnItemClickListener {

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        displayView(position, ScreenTransition.FADE);
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) {

    ColorDrawable colorDrawable = new ColorDrawable( Color.TRANSPARENT );
    getWindow().setBackgroundDrawable( colorDrawable );

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mTitle = getTitle();
    mFragManager = getFragmentManager();

    mNavMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

    mNavDrawerItems = new ArrayList<NavDrawerItem>();
    mNavMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);

    //Add Nav drawer items to array list
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[0], mNavMenuIcons.getResourceId(0, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[1], mNavMenuIcons.getResourceId(1, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[2], mNavMenuIcons.getResourceId(2, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[3], mNavMenuIcons.getResourceId(3, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[4], mNavMenuIcons.getResourceId(4, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[5], mNavMenuIcons.getResourceId(5, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[6], mNavMenuIcons.getResourceId(6, -1)));
    mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[7], mNavMenuIcons.getResourceId(7, -1)));

    mNavMenuIcons.recycle();
    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
    mAdapter = new NavDrawerListAdapter(getApplicationContext(), mNavDrawerItems);
    mDrawerList.setAdapter(mAdapter);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle
            (this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name,  R.string.app_name )
    {
        public void onDrawerClosed(View view) {
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null)
        displayView(0,ScreenTransition.NONE);

}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getActionBar().setTitle(mTitle);
}

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {

    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggles
    mDrawerToggle.onConfigurationChanged(newConfig);

}

// ******************   PARTICULARLY RELEVANT PART BELOW ******************

@Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
    mFragManager.putFragment(outState,FRAGMENT_TAG,fragment);
}
@Override
public void onRestoreInstanceState(Bundle inState) {
    super.onRestoreInstanceState(inState);
    fragment = mFragManager.getFragment(inState,FRAGMENT_TAG);
}

public void displayView(int position, ScreenTransition transition) {

    fragment = null;

    switch (position) {

    case HOME:
        fragment = new HomeFragment();
        break;

    case MY_LOANS:

        startActivity(new Intent(HomeActivity.this,MyLoansActivity.class));
        break;

    case PENDING_REQ:
        fragment = new FragmentOne();
        break;

    case BUSINESS_PROFILE:
        fragment = new FragmentTwo();
        break;

    case OWNERSHIP:
        fragment = new FragmentThree();
        break;

    case PROFILE:
        fragment = new FragmentFour();
        break;

    case NOTIF:
        fragment = new FragmentFive();
        break;

    case LOGOUT:
        mManager.logoutUser();
        break;

    }

    if (fragment != null) {

        //Replace fragment
        FragmentTransaction ft = mFragManager.beginTransaction();
        ft.replace(R.id.home_container, fragment, FRAGMENT_TAG);
        ft.addToBackStack(null).commit();

        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(mNavMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);


    }
}

}

Here's my logcat:

07-20 09:47:30.404: E/AndroidRuntime(1122): FATAL EXCEPTION: main
07-20 09:47:30.404: E/AndroidRuntime(1122): Process: com.opendoors.auth, PID: 1122
07-20 09:47:30.404: E/AndroidRuntime(1122): java.lang.NullPointerException
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.FragmentManagerImpl.putFragment(FragmentManager.java:563)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at com.opendoors.core.HomeActivity.onSaveInstanceState(HomeActivity.java:212)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.Activity.performSaveInstanceState(Activity.java:1153)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1223)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3175)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3234)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.ActivityThread.access$1100(ActivityThread.java:135)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1223)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.os.Looper.loop(Looper.java:136)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at android.app.ActivityThread.main(ActivityThread.java:5017)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at java.lang.reflect.Method.invokeNative(Native Method)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at java.lang.reflect.Method.invoke(Method.java:515)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-20 09:47:30.404: E/AndroidRuntime(1122):     at dalvik.system.NativeStart.main(Native Method)

I have little struggle with my Android App. I've made app that shows Map from google maps API, and my location, but I can't go further with this "Check" and how should I draw and import this "Area". I want to ask you if you know or have ideas how to do that? I've searched for about 3hours but I didn't find any clear answer. I'll be thanksfull if somebody helps me :)

My app uses the Google Analytics v3 only for Campaign Measurment and Uncaught Exceptions. The main problem is the Google Analytics is always running. (Takes about 12MB in memory). How can i prevent running in background? Here's how i use GA v3 In Application's onCreate

EasyTracker.getInstance(this);
ExceptionReporter myHandler = new ExceptionReporter(
                GoogleAnalytics.getInstance(c).getTracker("UA-66666-666"),
                GAServiceManager.getInstance(),
                Thread.getDefaultUncaughtExceptionHandler(),c);
        myHandler.setExceptionParser(new ExceptionParser() {
            @Override
            public String getDescription(String s, Throwable throwable) {
                return ExceptionLog.convertExceptionToString(throwable);
            }
        });
        Thread.setDefaultUncaughtExceptionHandler(myHandler);

In Activity onStart(); and onStop();

EasyTracker.getInstance(this).activityStart(this);
EasyTracker.getInstance(this).activityStop(this);

In AndroidManifest

<service android:name="com.google.analytics.tracking.android.CampaignTrackingService" />
        <receiver android:name="com.google.analytics.tracking.android.CampaignTrackingReceiver" android:exported="true">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER" />
            </intent-filter>
        </receiver>

I just new in android development. In fact I started it just earlier this afternoon. I follow the instruction in this link.

https://developer.android.com/training/basics/firstapp/creating-project.html

I just rename it as hello2.

Everything seems perfect except when I was trying to run it in AVD. My logcat keeps popping some errors. And the emulator display "Unfortunately, hello2 has stopped."

can somebody out there help me?

this is my java file

package com.example.hello2;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

this is my manifest file

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

and this is my logcat:

07-20 13:22:25.760: W/dalvikvm(960): threadid=1: thread exiting with uncaught exception (group=0xb3af1d70)
07-20 13:22:25.780: E/AndroidRuntime(960): FATAL EXCEPTION: main
07-20 13:22:25.780: E/AndroidRuntime(960): Process: com.example.hello2, PID: 960
07-20 13:22:25.780: E/AndroidRuntime(960): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hello2/com.example.hello2.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.os.Looper.loop(Looper.java:136)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.main(ActivityThread.java:5026)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invokeNative(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960):  at java.lang.reflect.Method.invoke(Method.java:515)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-20 13:22:25.780: E/AndroidRuntime(960):  at dalvik.system.NativeStart.main(Native Method)
07-20 13:22:25.780: E/AndroidRuntime(960): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.setContentView(Activity.java:1930)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
07-20 13:22:25.780: E/AndroidRuntime(960):  at com.example.hello2.MainActivity.onCreate(MainActivity.java:13)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Activity.performCreate(Activity.java:5242)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-20 13:22:25.780: E/AndroidRuntime(960):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-20 13:22:25.780: E/AndroidRuntime(960):  ... 11 more

I hope somebody can help me..

PS: sorry for the bad English.

Trying to do a simple text to speech app in android but i am getting NullPointerEception , i debugged and checked the text is being passed to the tts

Below is the code snippets i am using

private TextToSpeech tts;
ArrayList<String> text;


btnPlay = (Button) dialog.findViewById(R.id.btnPlayText);

                btnPlay.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        speakText();
                    }

                });



public void speakText() {
        String toSpeak = text.get(0);
        Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT)
                .show();
        tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        System.out.println();
    }

I am passing the text from "text" which is an arraylist containing the data i want to convert and play using tts

Error is shown at this line MainActivity.java:127

tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

Logcat shows the following

07-20 19:42:20.427: E/AndroidRuntime(19476): FATAL EXCEPTION: main
07-20 19:42:20.427: E/AndroidRuntime(19476): Process: com.android.speechtest, PID: 19476
07-20 19:42:20.427: E/AndroidRuntime(19476): java.lang.NullPointerException
07-20 19:42:20.427: E/AndroidRuntime(19476):    at com.android.speechtest.MainActivity.speakText(MainActivity.java:127)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at com.android.speechtest.MainActivity$3.onClick(MainActivity.java:111)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.view.View.performClick(View.java:4456)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.view.View$PerformClick.run(View.java:18465)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.os.Handler.handleCallback(Handler.java:733)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.os.Handler.dispatchMessage(Handler.java:95)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.os.Looper.loop(Looper.java:136)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at android.app.ActivityThread.main(ActivityThread.java:5086)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at java.lang.reflect.Method.invokeNative(Native Method)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at java.lang.reflect.Method.invoke(Method.java:515)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-20 19:42:20.427: E/AndroidRuntime(19476):    at dalvik.system.NativeStart.main(Native Method)
07-20 19:43:25.763: E/AndroidRuntime(20818): FATAL EXCEPTION: main
07-20 19:43:25.763: E/AndroidRuntime(20818): Process: com.android.speechtest, PID: 20818
07-20 19:43:25.763: E/AndroidRuntime(20818): java.lang.NullPointerException
07-20 19:43:25.763: E/AndroidRuntime(20818):    at com.android.speechtest.MainActivity.speakText(MainActivity.java:127)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at com.android.speechtest.MainActivity$3.onClick(MainActivity.java:111)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.view.View.performClick(View.java:4456)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.view.View$PerformClick.run(View.java:18465)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.os.Handler.handleCallback(Handler.java:733)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.os.Handler.dispatchMessage(Handler.java:95)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.os.Looper.loop(Looper.java:136)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at android.app.ActivityThread.main(ActivityThread.java:5086)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at java.lang.reflect.Method.invokeNative(Native Method)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at java.lang.reflect.Method.invoke(Method.java:515)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-20 19:43:25.763: E/AndroidRuntime(20818):    at dalvik.system.NativeStart.main(Native Method)
07-20 19:44:29.289: E/ActivityThread(21489): Performing pause of activity that is not resumed: {com.android.speechtest/com.android.speechtest.MainActivity}
07-20 19:44:29.289: E/ActivityThread(21489): java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.android.speechtest/com.android.speechtest.MainActivity}
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3084)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3072)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3050)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread.access$1000(ActivityThread.java:139)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1221)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.os.Handler.dispatchMessage(Handler.java:102)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.os.Looper.loop(Looper.java:136)
07-20 19:44:29.289: E/ActivityThread(21489):    at android.app.ActivityThread.main(ActivityThread.java:5086)
07-20 19:44:29.289: E/ActivityThread(21489):    at java.lang.reflect.Method.invokeNative(Native Method)
07-20 19:44:29.289: E/ActivityThread(21489):    at java.lang.reflect.Method.invoke(Method.java:515)
07-20 19:44:29.289: E/ActivityThread(21489):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-20 19:44:29.289: E/ActivityThread(21489):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-20 19:44:29.289: E/ActivityThread(21489):    at dalvik.system.NativeStart.main(Native Method)

Using a PHP file and MySQLI, data is passed from an Android app to a MySQL database. However, it seems that certain characters entered such as " " and "&" will cause wrong inputs. I have been able to use the Java replace function to fix " "'s but I'm sure there are many special characters available which will cause similar errors. For example: www.example.com?Input1=Test&Input.

I am wondering if there is a fix to prevent MySQLI from interpreting the input in this way.

Also, if it helps this is my PHP code:

<?php
//Open a new connection to the MySQL server
$mysqli = new mysqli('localhost','createyo_james','password','createyo_TestDatabase');

//Output any connection error
if ($mysqli->connect_error) {
    die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

//values to be inserted in database table
$NewsStory = $_GET["NewsStory"];
$Summary1 = $_GET["Summary1"];
$Summary2 = $_GET["Summary2"];
$Summary3 = $_GET["Summary3"];
$Picture1URL = $_GET["Picture1URL"];
$Picture2URL = $_GET["Picture2URL"];
$Picture3URL = $_GET["Picture3URL"];
$Picture4URL = $_GET["Picture4URL"];
$Picture5URL = $_GET["Picture5URL"];
$Tags = $_GET["Tags"];
$Body = $_GET["Body"];
$Sources = $_GET["Sources"];

var_dump($_GET["NewsStory"]);


$query = "INSERT INTO Articles (NewsStory, Summary1, Summary2, Summary3, Picture1URL, Picture2URL, Picture3URL, Picture4URL, Picture5URL, Tags, Body, Sources) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$statement = $mysqli->prepare($query);
var_dump($query);
//bind parameters for markers, where (s = string, i = integer, d = double,  b = blob)
$statement->bind_param('ssssssssssss', $NewsStory, $Summary1, $Summary2, $Summary3, $Picture1URL, $Picture2URL, $Picture3URL, $Picture4URL, $Picture5URL, $Tags, $Body, $Sources);

if($statement->execute()){
    print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />'; 
}else{
    die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();

?>

I am using a DatagramSocket to receive packets in background (using service). but it does not receive when my phone is locked while when I add a ScheduledTask to start the thread every 1 sec, it works well. Why it doesn't work in first case and how can I fix it whitout starting the Tread every 1 sec?

public class RecThread2 implements Runnable {

    public void run() {
      while(running){
        try {
            int MESSAGE_LEN = 60;
            byte[] recvBuffer = new byte[MESSAGE_LEN];
            DatagramPacket datagram = new DatagramPacket(recvBuffer,
                    MESSAGE_LEN);
            socket1.receive(datagram);
            String recvdString = new String(recvBuffer);
            Log.i("Recieved", recvdString);
            mess = recvdString;
        } catch (Exception e) {
            e.printStackTrace();
        }
      }
    }
}

and I run the thread here:

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    // TODO Auto-generated method stub
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "receiveTag");
    wl.acquire();

    Thread sThread2 = new Thread(new runSoc1());
    sThread2.start();

    return super.onStartCommand(intent, flags, startId);
}

But when I use the following code to run Thread periodically it works even when the phone is locked (and I remove the while(running) from the Thread code):

        time = new Timer();
        ScheduledTask st = new ScheduledTask();
        time.schedule(st, 0, 1000);

and :

public class ScheduledTask extends TimerTask {
    public void run() {
        Thread sThread2 = new Thread(new RecThread2());
        sThread2.start();
    }
} 

Can I ask question: how I can get money from adMob? Can I sent my money from adMob account to my bank's card? I know that for sending my balance must be > 100$

The list of image arraylist in 7. Then i,m increment by using i-- on swipe Right to Left. It should displayed in Second position of the image. But i,m decrements by using ++i on swipe Left to Right it should displayed correctly. So, i want to increment by 1 st position of the image.

I was following a tutorial on how to use surfaceView for an android app. Originally there is only one button swapBtn that animates either the black or white circle. However, I tried to modify it so once I clicked it, another button other would appear. However, once I do this, the first button swapBtn can no longer be clicked to switch between animating the white and black ball. I also get a error in the debug console saying:

Thread[<1> main] (Suspended ( exception NullPointerException))

How can I fix this so that I can show the second button while still being able to click the second button. Here is the relevant code. Any suggestions would be much appreciated.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_surface_view);

    swapBtn = (Button) findViewById(R.id.buttonswap);


    surface = (SurfaceView) findViewById(R.id.mysurface);
    holder = surface.getHolder();

    thread = new Thread(this);
    thread.start();
    swapBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            /** SWAP ANIMATION LEFT OR RIGHT CIRCLE*/
            left = !left;

            if (other.getVisibility() == View.VISIBLE)
            {
                other.setVisibility(View.GONE);
            }
            else if(other.getVisibility() == View.GONE)
            {
                other.setVisibility(View.VISIBLE);
            }
        }
    });
}

I am currently working on a project which include in image cropping. I am used image crop for "Cropper library". I want to image cropping like whats app. So, i have put this code in my project. But it's work only for square size cropping but it's square size is change but i want to it's size also fix. How can i fix that?

cropperimageView.setFixedAspectRatio(true);
cropperimageView.setAspectRatio(DEFAULT_ASPECT_RATIO_VALUES, DEFAULT_ASPECT_RATIO_VALUES);
cropperimageView.setGuidelines(0);

Hi I am using Skyepub SDK and I am able to read the epub using the same. My problem is that I am not able to get the Selection Listener working using the sample code given. I have implemented selection listener in the following way :

class SelectionDelegate implements SelectionListener {
    public void selectionStarted(Highlight highlight,Rect startRect,Rect endRect) {
        showButton();
    }; // in case user touches down selection bar, normally hide custom


    public void selectionChanged(Highlight highlight,Rect startRect,Rect endRect) {
    }; // this may happen when user dragging selection.

    public void selectionEnded(Highlight highlight,Rect startRect,Rect endRect) {

    }; 

    public void selectionCancelled() {
    } // selection cancelled by user.
}

and attached it to ReflowableControl in the following way:

rv.setSelectionListener(new SelectionDelegate());

when I long press on the text in the epub here is what is logged into logcat:

07-20 02:47:46.660: I/chromium(825): [INFO:CONSOLE(1)] "Uncaught TypeError: Object [object Object] has no method 'setResult'", source: http://localhost:58565/sample/OEBPS/ch13.xhtml (1)

I am trying to make my own face detecting android app, which is based on mixed-processing and face detection tutorial. It runs super slow on my device cca 2.5 FPS on 240x160 resolution.

I was trying to find the problem and make it faster, so one of the things I made was displaying result in greyscale instead of RGB. When I changed it back, I forget to delete line where I was drawing rectangles to Greyscale Mat (mGr).

But for my surprise, those were still appearing on the screen (those were white), with approx one frame delay after red ones from the RGB Mat. So there were both. How is this possible? I did not draw into mRGB mat any white rectangles :/

Here I call it in Java:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    final int viewMode = mViewMode;
    switch (viewMode) {        
       case VIEW_MODE_FEATURES:
        // input frame has RGBA format
        mRgba = inputFrame.rgba();
        mGray = inputFrame.gray();

        myDetect();//native function
        //Imgproc.cvtColor(mGray, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);

        break;
    }

    return mRgba;
}

And this is how it looks like in C++ part

    Mat& mGr = *(Mat*) addrGray;
    Mat& mRgb = *(Mat*) addrRgba;

    vector<Rect> highLight; // vector with rectangles to highlight detected items

    detect(mGr, highLight, env, stages);

    //highlight detected items on screen 
    for (unsigned int i = 0; i < highLight.size(); i++) {
        rectangle(mRgb, highLight[i], Scalar(255, 0, 0, 255),THICKNESS);
        //rectangle(mGr, highLight[i], Scalar(255, 0, 0, 255),THICKNESS);
          // if I leave this here uncommented, white rectangle ghost will appear on my screen both with desired red ones...
}

Anybody could guess how is this possible? Thanks in advance!

I'm doing this tutorial, but I'm having some trouble with understanding how to make this into one activity. (In the tutorial, you would have Main Activity and Display Message Activity, but for my purposes, I need it to be in one activity) I understand how everything works, but I just can't figure out how to make this into one activity. Any help is appreciated!

Here is the tutorial I'm working on: https://developer.android.com/training/basics/firstapp/building-ui.html

And I'll include my code below, but it's probably easier to see where I am in the tutorial (I'm at the step, "Starting Another Activity").

fragment_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="horizontal">
    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />
</LinearLayout>

MainActivity.java

package com.example.helloworld;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.content.Intent;
import android.os.Build;



public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null) {
            getFragmentManager().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();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            return rootView;
        }
    }

    public void sendMessage(View view) {
        Intent intent = new Intent(this, DisplayMessageActivity.class);
        EditText editText = (EditText) findViewById(R.id.edit_message);
        String message = editText.getText().toString();
        intent.putExtra(EXTRA_MESSAGE, message);
        startActivity(intent);
    }
}

i am new in Android. please help me How To Add Shimmer for Android Library in My Project Android Eclipse. here is link of Shimmer for Android

I'm new to android development. my app crashes when i use the code below, it works perfectly if i remove onclicklistner here is the code..

   int[] vmarray= {R.drawable.vm1bulb, R.drawable.vm2chair, R.drawable.vm3comb,
   R.drawable.vm4cycle,R.drawable.vm5dairy,R.drawable.vm6fan,R.drawable.vm7mobile,
   R.drawable.vm8pen,R.drawable.vm9shoes,R.drawable.vm10toothbrush,  
   R.drawable.vm11bangle, R.drawable.vm12watch};

        @Override
        protected void onCreate(Bundle savedInstanceState) {
     // TODO Auto-generated method stub

     super.onCreate(savedInstanceState);


    inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

     setContentView(R.layout.cacrvisualmem);

      firstview =(LinearLayout)this.findViewById(R.id.firsthumlayout);

    secondview = (LinearLayout) inflater.inflate(R.layout.cacrvisualmempart1, null);

   for(int i=0;i<6;i++)
     { 
     final int a = i;
     button_var[a] = (Button)findViewById(idArray[a]); 
     }

// IN FIRST LAYOUT, THERE ARE 6 BUTTONS AND THEIR BACKGROUND IS RANDOMLY SET
// DRAWABLES FROM ARRAY "vmarray". the following code is for that

     Random randomGenerator = new Random();
      Random rand6 = new Random();

     while (numbers.size() < 6) {
     random1 = randomGenerator.nextInt(12);
     random2 = rand6.nextInt(6);

      if (!numbers.contains(random1) && (!numbers2.contains(random2))) 
       {
           numbers.add(random1);

           numbers2.add(random2);  

           b[random2].setBackgroundResource(vmarray[random1]);
           count++;         

        }//if ends
     }//while ends

     Handler changeview = new Handler();

     Runnable r1 = new Runnable(){
        @Override
        public void run() {
            // TODO Auto-generated method stub

     // NOW, here, after 1 minute, second view will be inflated and button1  
     //  background is set to one the image from the array

            setContentView(secondview);

            b11=(Button)findViewById(R.id.button1);

            queryrandvar=queryrand.nextInt(12);

            switch(queryrandvar)
            {
            case 0:
                b11.setBackgroundResource(vmarray[0]);
                queryval=0;
                break;
            case 1:
                b11.setBackgroundResource(vmarray[1]);
                queryval=1;
                break;
            case 2:
                b11.setBackgroundResource(vmarray[2]);
                queryval=2;
                break;
            case 3:
                b11.setBackgroundResource(vmarray[3]);
                queryval=3;
                break;
            case 4:
                b11.setBackgroundResource(vmarray[4]);
                queryval=4;
                break;
            case 5:
                b11.setBackgroundResource(vmarray[5]);
                queryval= 5;
                break;
            case 6:
                b11.setBackgroundResource(vmarray[6]);
                queryval= 6;
                break;
            case 7:
                b11.setBackgroundResource(vmarray[7]);
                queryval= 7;
                break;
            case 8:
                b11.setBackgroundResource(vmarray[8]);
                queryval= 8;
                break;
            case 9:
                b11.setBackgroundResource(vmarray[9]);
                queryval= 9;
                break;
            case 10:
                b11.setBackgroundResource(vmarray[10]);
                queryval= 10;
                break;
            case 11:
                b11.setBackgroundResource(vmarray[11]);
                queryval= 11;
                break;

        }//switch ends


        }//run ends
     };//runnable ends

     b11.setOnClickListener(null);

     changeview.postDelayed(r1,10000);

  } //on create method ends here



    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch(v.getId())
    {
    case R.id.button1:
      {

       b11.setBackgroundResource(vmarray[1]);

       break;
      }




     }//switch ends
  }//onclick ends

if i remove onclicklistner, it runs perfectly fine, but implementing it crashes the app, what is wrong with my onclick method or onclick listner

I can't find any resources online, and need an answer ASAP.

I need to remove my app from the google play store, but when it goes back online, I would like its stats to still be there. Will this be the case?

So I have a project in my android class to build an app that can scan your hand and identify how many fingers are being held up. I can't really find a library off of a google search to do something incorporated with scanning an object. Any pointers for me?

I would like to use the Jmol open source molecular viewer library for visualizations within an Android application. I have not been able to find any resources that describe the use of Jmol in Android applications or even in just Java applications.

Am I mistaken in that Jmol can be used as I propose? Can you point me to any resources such as tutorials or the like that would assist me?

I am currently writing an Android app that functions as an internet radio. Part of the functionality of the app is that it is controllable via infrared remote. The infrared remote codes come in as analogue audio through the microphone port. If I record some of the signals and look at them in Audacity, it's very easy for me to see what each code is. For example, the following is 0111111010011001011111101000001 or 0x3F4CBF41. enter image description here My question is how can I programmatically detect these signals when they come in and convert them to integer code numbers. I have looked into some packaged solutions like LIRC, but they're written in C and would be difficult to integrate. It also seems to me like native would be over kill to do such simple analysis. I also looked into libraries like musicg, but I couldn't find any easy way to convert the codes in real time.

I'm using libgdx. I want to scale image button on touchDown listener, but scaleBy not work.

I try with alpha or move methods and both method work fine, except scaleBy.

Here is me code:

    buttonSettings.addAction(Actions.scaleBy(5f, 5f, 0.5f)); //NOT WORKING
    buttonSettings.addAction(Actions.alpha(0.4f, 0.2f));//WORKING GOOD

Any suggestion ?

Thanks for help