Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:54:44+00:00 2026-05-30T13:54:44+00:00

hey there guys and girls, iv been trying to fix this problem for weeks

  • 0

hey there guys and girls, iv been trying to fix this problem for weeks now and carnt seem to get any help, i want the code to download a JSON file from my server and the save it to internal memory with the saveJSON() and then with the showJSON() it should display the saved JSON file and then decode it to plain text. the problems i get are around HttpResponse and the next line and also im not sure it the next section is also write where it should save the JSON file. here are the two errors im getting

Error in http connection java.net.SocketException: Permission denied 

and

Error saving string null.pointer

any help would be greatly appreciated

    public class MainActivity extends Activity {

String storyObj = "";
Object json = null;
HttpEntity entity = null;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    //button that saves the file from mySQL
    Button save = (Button) findViewById(R.id.downloadBtn);
    save.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveJson();             
        }
    });

    //Button that opens the file from InternalMemory
    Button open = (Button) findViewById(R.id.showBtn);
    open.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            openJson();             
        }
    });


//end of onCreate() 
}


//saveJson pull a JSON file from mySQl server then saves that file in its JSON type eg .json
public void saveJson(){
    TextView test = (TextView) findViewById(R.id.showView);


    try{
        //connects to mySQL
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("http://10.0.2.2/textures_story_list.php");
        HttpResponse response = client.execute(post);
        //captures the response
        entity = response.getEntity();

    }catch(Exception e) {
         Log.e("log_tag", "Error in http connection "+e.toString());
    }
    try{
        Object json = entity;
        String FILENAME = "story.json";
        //gives file name
        FileOutputStream output = openFileOutput(FILENAME, MODE_WORLD_READABLE);
        //creates new StreamWriter
        OutputStreamWriter writer = new OutputStreamWriter(output);
        //writes json with file name story.json
        writer.write((Integer) json);
        writer.flush();
        //closes writer
        writer.close();

    }catch(Exception e) {
         Log.e("log_tag", "Error saving string "+e.toString());
    }

//end of saveJson()
}

private char[] Object(Object json2) {
    // TODO Auto-generated method stub
    return null;
}


public void openJson(){
    TextView test = (TextView) findViewById(R.id.showView);



    try{
        FileInputStream fileInput = openFileInput("story.json");

        BufferedReader inputReader = new BufferedReader(new InputStreamReader(fileInput, "UTF-8"), 8);
        StringBuilder strBuilder = new StringBuilder();
            String line = null;
            while ((line = inputReader.readLine()) != null) {
                strBuilder.append(line + "\n");
            }
            fileInput.close();
            storyObj = strBuilder.toString();

    }catch(IOException e){
         Log.e("log_tag", "Error building string "+e.toString());
    }

    try{
        JSONArray jArray = new JSONArray(storyObj);
        String storyNames = "";
        for(int i = 0;i<jArray.length();i++){
            storyNames += jArray.getJSONObject(i).getString("story_name") +"\n";
        }
        test.setText(storyNames);

    }catch(JSONException e) {
         Log.e("log_tag", "Error returning string "+e.toString());
    }
    return;
//and of openJson() 
}




//end of class body    
}

and here is my xml manifest

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

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

<users-permission
    android:name="android.permission.INTERNET"  />
<users-permission   android:name="android.permission.SET_DEBUG_APP" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
     android:debuggable="true">

    <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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:54:46+00:00Added an answer on May 30, 2026 at 1:54 pm

    If this really is your Manifest file, the error is obvious .The tags should not be use[r]s-permission, but uses-permission:

    <uses-permission
        android:name="android.permission.INTERNET"  />
    <uses-permission   android:name="android.permission.SET_DEBUG_APP" />
    

    Now you wouldn’t have access to internet, and thus the error. If you switch to using an IDE like Eclipse and use autocomplete you will avoid such errors from the very beginning, but furthermore the IDE will underline this mistakes as warnings.

    EDIT: About the error you get – you are trying to cast the entity of the response directly to an Integer. This will always fail, because Integer is not superclass of HttpEntity. You need to read the contents of the entity in a String and then parse the contents of the string to integer:

    InputStream entityStream = entity.getcontent();
    StringBuilder entityStringBuilder = new StringBuilder();
    byte [] buffer = new byte[1024];
    int bytesReadCount;
    while ((bytesReadCount = entityStream.read(buffer)) > 0) {
        entityStringBuilder.append(new String(buffer, 0, bytesReadCount));
    }
    String entityString = entityStringBuilder.toString();
    Integer responseInteger = Integer.valueOf(entityString);
    

    this is not highly optimized, but does the job. From then on you can use the responseInteger value as you like . However if you want to do writer.write you will need String value, not Integer. Thus I recommend you to use entityString.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys and girls, i'm stumped. Trying to get array_search to work with this
Hey there, I am trying to get my signout button to work. This is
hey there guys and girls i have this code that saves json as a
Hey there! I'm doing this project and right now I'm trying to: create some
hey there guys and girls i have this code that should download a json
Hey guys, quick question for any experts out there. I am allowing users to
Hey guys, one more quick question for any experts out there. I have a
Hey guys, I'm working on a status-Updater. It works, there is just one problem,
Hey there guys, this is my first question on Stack Overflow. I figured this
Hey guys I was wondering if there is a way to get a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.