no errors but still app force closes in android studio : <p>I am trying to make an app to take an image when the button is clicked and then take that image and place it in the image view field.
The given code is fine with no errors, i have checked many times. Still i get this error of runtime exception even when i have instanciated the activity in the manifest file.</p>

<p>here is xml code:</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="10"
    tools:context="com.example.android.tryingcamera.MainActivity"&gt;
&lt;ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="9"/&gt;
&lt;Button
    android:id="@+id/btnCamera"
    android:layout_weight="1"
    android:text="Tap To Open Camera"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="btncameraClicked"/&gt;
</code></pre>

<p></p>

<p>here is java code:</p>

<pre><code>public class MainActivity extends AppCompatActivity {

private ImageView imageview=(ImageView)findViewById(R.id.imageView);
private Button btncamera = (Button) findViewById(R.id.btnCamera);
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}



public void btncameraClicked(View view){
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent,0);
}

@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data ){
    super.onActivityResult(requestCode,resultCode,data);
    Bitmap bitmap=(Bitmap)data.getExtras().get("data");
    imageview.setImageBitmap(bitmap);
}
</code></pre>

<p>}</p>

<p>The logcat show this:</p>

<pre><code>Process: com.example.android.tryingcamera, PID: 27769
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.tryingcamera/com.example.android.tryingcamera.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2567)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
    at android.support.v7.app.AppCompatDelegateImplBase.&lt;init&gt;(AppCompatDelegateImplBase.java:117)
    at android.support.v7.app.AppCompatDelegateImplV9.&lt;init&gt;(AppCompatDelegateImplV9.java:149)
    at android.support.v7.app.AppCompatDelegateImplV11.&lt;init&gt;(AppCompatDelegateImplV11.java:29)
    at android.support.v7.app.AppCompatDelegateImplV14.&lt;init&gt;(AppCompatDelegateImplV14.java:54)
    at android.support.v7.app.AppCompatDelegateImplV23.&lt;init&gt;(AppCompatDelegateImplV23.java:31)
    at android.support.v7.app.AppCompatDelegateImplN.&lt;init&gt;(AppCompatDelegateImplN.java:31)
    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:198)
    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:183)
    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
    at android.support.v7.app.AppCompatActivity.findViewById(AppCompatActivity.java:190)
    at com.example.android.tryingcamera.MainActivity.&lt;init&gt;(MainActivity.java:14)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2557)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
    at android.app.ActivityThread.-wrap12(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6119) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at 

com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
</code></pre>
