0

I am getting a Null Pointer Exception at customWebView.loadUrl. I mentioned that error at end of the line.I doesn't know how to solve these Error.

StackTrace:

 E/AndroidRuntime(1353): FATAL EXCEPTION: main
 E/AndroidRuntime(1353): Process: com.gems.android, PID: 1353
 E/AndroidRuntime(1353): java.lang.NullPointerException
 E/AndroidRuntime(1353):    at libcore.net.UriCodec.decode(UriCodec.java:153)
 E/AndroidRuntime(1353):    at java.net.URLDecoder.decode(URLDecoder.java:45)
 E/AndroidRuntime(1353):    at com.sit.fth.frgment.MagazineDetailFragment.onCreateView(MagazineDetailFragment.java:38)
 E/AndroidRuntime(1353):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
 E/AndroidRuntime(1353):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
 E/AndroidRuntime(1353):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
 E/AndroidRuntime(1353):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
 E/AndroidRuntime(1353):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
 E/AndroidRuntime(1353):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
 E/AndroidRuntime(1353):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
 E/AndroidRuntime(1353):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
 E/AndroidRuntime(1353):    at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
 E/AndroidRuntime(1353):    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
 E/AndroidRuntime(1353):    at android.view.View.measure(View.java:16497)
 E/AndroidRuntime(1353):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
 E/AndroidRuntime(1353):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
 E/AndroidRuntime(1353):    at android.view.View.measure(View.java:16497)
 E/AndroidRuntime(1353):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
 E/AndroidRuntime(1353):    at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327)
 E/AndroidRuntime(1353):    at android.view.View.measure(View.java:16497)
 E/AndroidRuntime(1353):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
 E/AndroidRuntime(1353):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
 E/AndroidRuntime(1353):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
 E/AndroidRuntime(1353):    at android.view.View.measure(View.java:16497)
 E/AndroidRuntime(1353):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1916)
 E/AndroidRuntime(1353):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1113)
 E/AndroidRuntime(1353):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1295)
 E/AndroidRuntime(1353):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
 E/AndroidRuntime(1353):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
 E/AndroidRuntime(1353):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
 E/AndroidRuntime(1353):    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
 E/AndroidRuntime(1353):    at android.view.Choreographer.doFrame(Choreographer.java:544)
 E/AndroidRuntime(1353):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
 E/AndroidRuntime(1353):    at android.os.Handler.handleCallback(Handler.java:733)
 E/AndroidRuntime(1353):    at android.os.Handler.dispatchMessage(Handler.java:95)
 E/AndroidRuntime(1353):    at android.os.Looper.loop(Looper.java:136)
 E/AndroidRuntime(1353):    at android.app.ActivityThread.main(ActivityThread.java:5017)
 E/AndroidRuntime(1353):    at java.lang.reflect.Method.invokeNative(Native Method)
 E/AndroidRuntime(1353):    at java.lang.reflect.Method.invoke(Method.java:515)
 E/AndroidRuntime(1353):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
 E/AndroidRuntime(1353):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
 E/AndroidRuntime(1353):    at dalvik.system.NativeStart.main(Native Method)

MagazinDetailFragment.java:

package com.sit.fth.frgment;

import java.net.URLDecoder;

import android.os.Bundle;
//import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.gems.android.R;
import com.sit.fth.app.BaseFragment;
import com.sit.fth.util.CustomWebView;

public class MagazineDetailFragment extends BaseFragment{

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        this.setHasOptionsMenu(true);

        String url=getArguments().getString("url");
        View view=inflater.inflate(R.layout.magzine_detail, null);

        ((TextView) view.findViewById(R.id.header)).setText(getArguments().getString("title"));

        CustomWebView customWebView=new CustomWebView(getActivity());
        FrameLayout frameLayout=(FrameLayout) view.findViewById(R.id.webmagzine);
        frameLayout.addView(customWebView);
        ////AppLog.v("URL---->", "URLMAG"+url);

        customWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="+URLDecoder.decode(url));  <----38th Line Error


          view.findViewById(R.id.blog_back).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    getActivity().onBackPressed();

                }
            });

        return view;
    }
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        menu.clear();
        inflater.inflate(R.menu.main_menu, menu);
    }   

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.menuitem_back:
            getActivity().onBackPressed();
            break;

        default:
            break;
        }

        return true;
    }

}

Anybody can help me if you know how to solve these.Thank you.

2
  • Check your URL is null or not.Why are you decode it? Directly add that URL Commented Jun 6, 2014 at 6:43
  • @SimplePlan then what I have to do? Commented Jun 6, 2014 at 6:45

1 Answer 1

1

Actually you are not getting null value here:

String url=getArguments().getString("url");

Use this to avoid exception

if(url!=null){
customWebView.loadUrl("http://docs.google.com/gview?embedded=true&url="+URLDecoder.decode(url));}
else{
 Log.e("message","NULL value");
}
Sign up to request clarification or add additional context in comments.

1 Comment

It seems to be a right answer.Bcoz it solved my error.Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.