Results 1 to 17 of 17
  1. #1
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Java.lang.RuntimeException in Android

    XML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <manifest 
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="org.demo2"
        android:versionCode="1"
        android:versionName="1.0">
        <uses-sdk
            android:minSdkVersion="9"
            android:targetSdkVersion="18" />
        <application
            android:name="org.demo2.GAPT"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name">
            <activity 
                android:name="org.demo2.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>
            <activity
                android:name="org.demo2.KnowledgeBase">
            </activity>
            <activity
                android:name="org.demo2.LanguageProcessor">
            </activity>
        </application>
    </manifest>
    my XML manifest file.
    I have 3 classes:
    GAPT.java
    KnowledgeBase.java
    LanguageProcessor.java
    all in the same package org.demo2
    my Main Activity is GAPT.java (below)

    Java Code:
    package org.demo2;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.ScrollView;
    import android.widget.TextView;
    
    
    public class GAPT extends Activity 
    {
        @Override
    	public void onCreate(Bundle savedInstanceState)
    	{
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                ScrollView sv = new ScrollView(this);
                LinearLayout ll = new LinearLayout(this);
                ll.setOrientation(LinearLayout.VERTICAL);
                sv.addView(ll);
                LanguageProcessor L = new LanguageProcessor("user",ll);
                final TextView tv = new TextView(this);
                final EditText et = new EditText(this);
                et.setText("Your command here");
                Button b = new Button(this);
                b.setText("Ask Pad.me");
                String S="";
                b.setOnClickListener(new View.OnClickListener() 
                {@Override
                    public void onClick(View v) 
                    {
                        tv.setText(et.getText());
                    }
                });
                L.NLPquery(tv.getText().toString(),ll);
            }
    }
    and it is the only of the 3 class with an OnCreate() function
    aside from the Android SDK and io.commons I don't have any other files in my library

    when I try load the apk file on my phone,
    GAPTAndroidJava-debug.apk produced by Netbeans Build and Clean function, log cat returns:

    java.lang.RuntimeException: Unable to instantiate activiyy ComponentInfo{org.demo2/org.demo2.MainActivity}:java.lang.ClassNotFoundExc eption:Didn't find class "org.demo2.MainActivity" on path: /data/app/org.demo2-2.apk
    Caused by: java.lang.ClassNotFoundException: Didn't find class "org.demo2.MainActivity" on path:/ data/app/org/demo2-2.apk

    even though I changed the Android name to org.demo2.GAPT in my Manifest <application> tag, the app still shows up as MainActivity on my phone

  2. #2
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    Ok I fixed that problem by changing the app name in my strings.xml file BUT I have a new problem now

    I'm getting a null pointer exception on the constructor for LanguageProcessor even though the .java file is clearly defined and in the same package as my Main Activity

    java.lang.RuntimeException: Unable to start activity ComponentIfo{org.demo2/org.demo2.GAPT}: java.lang.NullPointerException
    at org.demo2.GAPT.onCreate(GAPT.java:23)

    Java Code:
    Boolean truth = true;
        ArrayList<String> npt = new ArrayList<String>();
        ArrayList<ArrayList<String>> input = new ArrayList<ArrayList<String>>();
        ArrayList<Boolean> check;
        KnowledgeBase KB;
        public LanguageProcessor(String user, LinearLayout ll) // this constructor initializes the class by giving value to the class variable, and loading the knowledge base
        {
            check = new ArrayList<Boolean>();
        	//new queries are created to act as prolog queries inside the JVM by using the following syntax
        	KB = new KnowledgeBase();
            TextView tv = new TextView(this);
            tv.setText("Hello "+user+", how may I help you?");
            ll.addView(tv);
            // where the 1st parameter of the Query/2 constructor is the type of prolog query, and the 2nd parameter is an array of all the terms used
        }
    My constructor

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    What is null on line 23?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    LanguageProcessor L = new LanguageProcessor("user",ll);

    it's referring to this line, I don't understand what it means by a null pointer though, I've written down the class path in the Manifest xml file, the class is in the same package as my main activity, it's constructed well according to my compiler, and the constructor is called well. Unless it's something to do with how I defined that <activity> in my XML file I don't see how this is a problem

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    I don't know if a call to a constructor will cause a NullPointerException. Are you sure that is line 23?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    I think it might be treating LanguageProcessor as a null object because it's not finding it in the package (even though it's inside there, I've checked). Since I'm referencing the constructor in that object it could be that I'm referencing a method in a null object or something like that

    should I define my other 2 activities the same way as the first one?
    XML Code:
    <activity
                android:name="org.demo2.LanguageProcessor"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    XML Code:
    <activity
                android:name="org.demo2.KnowledgeBase"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    respectively or is there something in that definition that defines them as main activities in themselves? (or some other way to fix this)

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    Are you sure which line is 23?

    I don't know about activities and NPE.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    I dont think it would make sense if 23 was any other line, don't think any Views can give null pointers, and the NLPquery() method would only return a null pointer exception if it's coming from a null object anyway

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    I dont think it would make sense if 23 was any other line
    You don't get to choose which line in #23. It's given by its position in the source.

    You get a NPE anytime the code tries to reference with a null variable.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    Ok I managed to find the full error:
    FATAL EXCEPTION: main
    java.lang.RuntimeException:Unable to start activity ComponentInfor{org.demo2/org.demo2.GAPT}: java.lang.NullPointerException
    at Android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2249)
    at Android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2299)
    at Android.app.ActivityThread.Access$700(ActivityThre ad.java:154)
    at Android.app.ActivityThread.handleMessage(ActivityT hread.java:2148)
    at android.os.Handler.dispatchMessage(Handler.java:99 )
    at android.os.Looper.loop(Looper.java:137)
    at Android.app.ActivityThread.main(ActivityThread.jav a:5306)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygotInit.java:1102)
    at com.android.internal.os.ZygotInit.main(ZygoteInit. java:869)
    at dalvik.system.NativeStart.main(NativeMethod)
    Caused by: java.lang.NullPointerException
    at android.content.ContextWrapper.getResources(Contex tWrapper.java:89)
    at android.content.ContextThemeWrapper.getResources(C ontextThemeWrapper.java:78)
    at android.view.View.<init>(View.java:3370)
    at android.view.View.<init>(View.java:3434)
    at android.widget.textView.<init>(TextView.java:816)
    at android.widget.textView.<init>(TextView.java:811)
    at android.widget.textView.<init>(TextView.java:807)
    at org.demo2.LanguageProcessor.<init>(LanguageProcess or.java:30)
    at org.demo2.onCreate(GAPT.java:22)
    at android.app.Activity.performCreat(Activity.java:52 55)
    at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1097)
    at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2213)

    . . . 11 more

    quite a long error message - does that mean there's a lot of bugs or is it just 1 very long one?

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    These two lines look important:
    at org.demo2.LanguageProcessor.<init>(LanguageProcess or.java:30)
    at org.demo2.onCreate(GAPT.java:22)
    Look at line 30 in LanguageProcessor for a null value.

    The stack trace shows what calls were being made when the exception happened.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    TextView tv = new TextView(this);
    that's line 30
    did I instantiate the TextView wrongly?

    Java Code:
    public LanguageProcessor(String user, LinearLayout ll) // this constructor initializes the class by giving value to the class variable, and loading the knowledge base
        {
        	//new queries are created to act as prolog queries inside the JVM by using the following syntax
        	KB = new KnowledgeBase();
            TextView tv = new TextView(this);
            tv.setText("Hello "+user+", how may I help you?");
            ll.addView(tv);
            // where the 1st parameter of the Query/2 constructor is the type of prolog query, and the 2nd parameter is an array of all the terms used
        }
    (my full constructor)

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    I have done much creating of GUI components in the code. I've left that in the XML.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    but then how will I know when the GUI components will show up?

    I've got a lot of GUI components just supposed to be used at certain moments not all throughout

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default Re: Java.lang.RuntimeException in Android

    I don't know about that. My GUI has been simple and defined in the XML.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    XML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        >
    
    <EditText android:id="@+id/edit_message"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />
    <TextView android:id="@+id/edit_message"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:hint="@string/edit_message" />
     <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/button_send" />
    </LinearLayout>

  17. #17
    EBamber is offline Member
    Join Date
    Apr 2014
    Posts
    30
    Rep Power
    0

    Default Re: Java.lang.RuntimeException in Android

    I just remembered I already defined a linearlayout

Similar Threads

  1. Replies: 8
    Last Post: 03-27-2013, 10:30 AM
  2. Replies: 2
    Last Post: 10-30-2009, 12:55 PM
  3. Replies: 0
    Last Post: 07-06-2009, 03:38 PM
  4. Replies: 4
    Last Post: 06-24-2009, 07:34 AM
  5. java.lang.RuntimeException+ Axis
    By Peter in forum Advanced Java
    Replies: 1
    Last Post: 07-05-2007, 02:43 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •