Soru & Cevap

FATAL EXCEPTION: main

02.10.2015 - 10:52

çalıştırınca bu sorunu alıyorum

logcat eror

Process: com.example.mustafa.barkod, PID: 10730
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mustafa.barkod/com.example.mustafa.barkod.MainActivity}: java.lang.NullPointerException
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2318)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
            at com.example.mustafa.barkod.MainActivity.onCreate(MainActivity.java:23)
            at android.app.Activity.performCreate(Activity.java:5411)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
            at android.app.ActivityThread.access$800(ActivityThread.java:139)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
            at dalvik.system.NativeStart.main(Native Method)

activity java 

public class MainActivity extends AppCompatActivity {

    Button ogren;
    EditText girdi;
    TextView goster;

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

        ogren.findViewById(R.id.button);
        girdi.findViewById(R.id.editText);
        goster.findViewById(R.id.textView);

        girdi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int giri = Integer.parseInt(girdi.getText().toString());
                int sayi [] = {1,2,3,4,5,6,7,8,9,};
               if(giri == sayi.length)
               {
                   goster.getText();
               }
            }
        });


    }


}

activity main xml

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/editText"
        android:layout_marginTop="74dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="New Text"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_alignBottom="@+id/editText" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />
</RelativeLayout>

android manifest

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/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>

 

5 Görüntülenme

3 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-7541-1521024507.jpg
burhanaras
10.10.2015 - 11:55
 ogren.findViewById(R.id.button);
        girdi.findViewById(R.id.editText);
        goster.findViewById(R.id.textView);

Bu satırlardaki noktaları "=" ile değişmen gerekli.

 ogren=findViewById(R.id.button);
        girdi=findViewById(R.id.editText);
        goster=findViewById(R.id.textView);

 

Profile picture for user yahyacan55
yahyacan55
02.10.2015 - 04:56

girdi.findViewById(R.id.editText);

Bunları bu şekilde kullanmazsın.

girdi = (EditText)findViewById(R.id.editText); // Bu şekilde kullanırsın. girdi null şu anki koda göre ondan patlıyor.

picture-7307-1432542084.jpg
rooest
02.10.2015 - 11:48
 <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>

Manifest.xml'  i  (intent-filter' in içini)  Yukarıdaki  gibi tekrar düzenleyip deneyebilir misin?