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 6767915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:00:31+00:00 2026-05-26T15:00:31+00:00

I have a question that, Iam xoring the first 2^21 bytes of a video

  • 0

I have a question that, Iam xoring the first 2^21 bytes of a video file with an another byte array, but it gives a Null Pointer Exception while Xoring the bytes, I don’t know why? Please suggest me the right answer of the same.

Thanks in advance.

Error Stack:

11-04 12:28:49.283: ERROR/AndroidRuntime(506): FATAL EXCEPTION: main
11-04 12:28:49.283: ERROR/AndroidRuntime(506): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.TestCryptoActivity}: java.lang.NullPointerException
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.os.Looper.loop(Looper.java:123)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at java.lang.reflect.Method.invokeNative(Native Method)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at java.lang.reflect.Method.invoke(Method.java:521)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at dalvik.system.NativeStart.main(Native Method)
11-04 12:28:49.283: ERROR/AndroidRuntime(506): Caused by: java.lang.NullPointerException
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at com.example.TestCryptoActivity.onCreate(TestCryptoActivity.java:132)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-04 12:28:49.283: ERROR/AndroidRuntime(506):     ... 11 more

Code:

String str;
    StringBuffer strBuf = new StringBuffer();
    String episode="E0022505.mp4";
    int bytesRead;

    InputStream is;
    byte[] bytesafterXor;
    byte[] bytes;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        File file = new File("/sdcard/E0022505.mp4");
        try {
               is = new FileInputStream(file);
        } catch (FileNotFoundException e2) {
               e2.printStackTrace();
        }
        byte[] fileData = new byte[2097152];
        int read = 0;
        while(read != fileData.length) {
           try {
            read += is.read(fileData, read, fileData.length - read);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bos.write(fileData,0,read);
        bytes = bos.toByteArray();
        try {
            String byteString = new String(bytes,"UTF-8");
            System.out.println("the bytes array of video:"+byteString);
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String data = "xyzzy734499639E0022505@a2+;%d3-";


        try {
            str = getHashCode(data);
            strBuf.append(str);
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }catch(Exception e)
        {
            e.printStackTrace();
        }


        for(int i=1;i<31;i++)
        {
            if(i<10)
            {
                str = String.valueOf(30)+String.valueOf(30+i)+str;
                try {
                    str = new String(getHashCode(str));
                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }else
            {
                char[] num = String.valueOf(i).toCharArray();
                String firstIndex = String.valueOf(num[0]);
                String secondIndex = String.valueOf(num[1]);
                str = firstIndex + secondIndex+ str;
                try {
                    str = new String(getHashCode(str));
                } catch (NoSuchAlgorithmException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            strBuf.append(str);
            System.out.println("The final string after hashing:"+strBuf.toString());
        }
        for(int j=0;j<bytes.length;j+=1024)
        {
            String str = strBuf.toString();
            byte[] newByte = str.getBytes();
            for(int k=0;k<str.getBytes().length;k++)
            {
                bytesafterXor[k] = (byte)((newByte[k]^bytes[k])& 0x000000ff);// this is the error position
                //System.out.println("The result after Xoring:"+bytesafterXor[k]);
            }
        }
    }
  • 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-26T15:00:32+00:00Added an answer on May 26, 2026 at 3:00 pm

    EDIT: Okay, I’ve just seen the comment saying “this is the error position” – it was mostly hidden, which made it harder to see.

    The answer is simple – you’ve never allocated bytesafterXor. You need something like:

    bytesafterXor = new byte[newByte.length];
    

    just before the k loop.

    However, you should also read the rest of this answer to correct other bad practices.


    You’ve posted a lot of code without showing where the stack trace is pointing, but I suspect the problem could well be due to one of the several blocks you’ve got like this:

    try {
           is = new FileInputStream(file);
    } catch (FileNotFoundException e2) {
           e2.printStackTrace();
    }
    

    If the file isn’t found, is is still going to be null afterwards… leading to a NullPointerException when you try to use it. Basically whenever you run into an exception, you’re currently just trying to carry on regardless, with no attempt to take account of the fact that the previous operation has just failed.

    I suggest you create a separate method which is declared to throw IOException (and anything else which might be thrown) and call that from your onCreate method. Then have just one catch block (in onCreate) so that if anything goes wrong in the “inner” method, you don’t keep trying to carry on with it regardless.

    Additionally:

    • I see no reason for is (etc) to be instance variables rather than local variables
    • You should close all your streams and any other unmanaged resources in finally blocks
    • Your code would be considerably easier to understand and debug if you refactored it into small methods.
    • I’m not an Android developer, but I doubt that doing all of this work in an onCreate method is good practice anyway – shouldn’t you be doing this in a background thread?
    • Using String.getBytes() without specifying an encoding is generally a bad idea, and this:

      for(int k=0;k<str.getBytes().length;k++)
      

      … is going to create a new byte array on every iteration. You’ve created a byte array (newByte) – why aren’t you using newByte.length?

    • It’s not clear what this loop is meant to achieve:

      for(int j=0;j<bytes.length;j+=1024)
      

      given that you’re not using the value of j within the loop…

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

Sidebar

Related Questions

I have a question on streaming output of libx264. My scenario is that Iam
I have a question that may have been answered over 9000 times before but
I have a question that is similar, but not identical, to the one answered
I have a question that I have been trying to figure out, but I
I have a question that must surely seem very trivial, but the answer has
I have a quick question that I can't seem to find online. I am
I have a simple question that I am posing mostly for my curiousity. What
I am learning C++ and have got a question that I cannot find the
I have a question regarding my database design and its implementation that i am
So I have a question. I have chatting/IM website that I am working on

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.