Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir, I am a beginner in Java.I have many doubts in building an apk using java program.I have referred many websites including codeproject, stack overflow and got few ideas in developing an android application.

What I did is:
1. Downloaded Android studio and built a signed apk(Successful build).
2. Copied the apk_release.apk to my phone and installed it(Successful installation).
3. when I opened the installed .apk it shows me "unfortunately KLUVIS(my file name) has stopped.
4. Using developers settings in my android phone I have enabled USB debugging and installed the app using adb.exe.But the same problem which I have encountered.
5. Referred various procedures in internet but didn't work.
6. Referring articles in codeproject.

Here is my .java code:
Java
package com.vis.vis;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class VIS extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_vis);
        final Button btn = (Button)findViewById(R.id.button1);
        final EditText et1 = (EditText)findViewById(R.id.editText1);
        final EditText et2 = (EditText)findViewById(R.id.editText2);
        final EditText et3 = (EditText)findViewById(R.id.editText3);
        final EditText et4 = (EditText)findViewById(R.id.editText4);
        final TextView result = (TextView)findViewById(R.id.textView1);
        btn.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                int s1 = new Integer(et1.getText().toString());
                int s2 = new Integer(et2.getText().toString());
                int s3 = new Integer(et3.getText().toString());
                float a = new Integer(et4.getText().toString());
                float end;
                end = (float) (((s1  + s2  + s3 ) / 7.5) + (a / 10));
                if(end<=40)
                {
                    end = (40 - end)*2;
                    result.setText("The marks needed to pass in your end semester:  " +end);
                }
                else
                {
                    end = (end - 40)/2;
                   result.setText("Additional marks that you have :"+end);
                }

            }
        });

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "visweswaran.nagasivam98@gmail.com", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_vi, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    }


and here is my .xml code:

XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="wrap_content" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:showIn="@layout/activity_vis"
    tools:context=".VIS">

    <TextView android:text="Kalasalingam University Mark Calculator" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView android:text="\n\nProgrammed by Er.N.Visweswaran.,B.Tech.,DMO.,DCP.," android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <TextView android:text="\n\nEnter your sessional one marks:  " android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>
    <TextView android:text="\n\nEnter your sessional two marks:  " android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" />
    <TextView android:text="\n\nEnter your sessional three marks:  " android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" />
    <TextView android:text="\n\nEnter your assignment marks:  " android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/editText4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" />
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CALCULATE" />
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />



</RelativeLayout>


Have I missed anything?Kindly help me with this.
Posted
Comments
Afzaal Ahmad Zeeshan 10-Nov-15 14:04pm    
The environment may not be fulfilling the requirements.

The solution would be to debug the application on your device. Set up "USB Debugging" and then debug it in that device.
[no name] 10-Nov-15 14:09pm    
Yes Sir, tried that too but not works.My app installs successfully but on opening it says "Unfortunately (my app name) has stopped". Is there any errors in my program?Kindly help me Sir.
Afzaal Ahmad Zeeshan 10-Nov-15 14:15pm    
Yes, there are errors. The solution is to use your own mobile device as the emulator and debugger. Attach the mobile with your laptop and then debug your application. Your IDE will show you the errors and you can then fix them.
[no name] 10-Nov-15 14:19pm    
Yes Sir, I have tried using an emulator but it simply shows "android" for more than an hour.
Afzaal Ahmad Zeeshan 10-Nov-15 14:24pm    
I am not talking about emulator, I am talking about your own device. Connect it using USB port.

1 solution

First of all my sincere Thank you to

1. Sir Richard MacCutchan,
2. Sir Mohibur Rashid,
3. Sir Afzaal Ahmad Zeeshan.

for their patient, kind and sincere help.The question is finally solved by removing some complexity, connecting my device to PC and running the application directly on virtual device.

Modified code:(Simplified by eliminating toolbars,name etc.,)
Java
package com.vis.vis;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class VIS extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_vis);
        final Button btn = (Button)findViewById(R.id.button);
        final EditText et1 = (EditText) findViewById(R.id.editText);
        final EditText et2 = (EditText)findViewById(R.id.editText2);
        final EditText et3 = (EditText) findViewById(R.id.editText3);
        final EditText et4 = (EditText) findViewById(R.id.editText4);
        final TextView result = (TextView) findViewById(R.id.textView);
        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                int s1 = new Integer(et1.getText().toString());
                int s2 = new Integer(et2.getText().toString());
                int s3 = new Integer(et3.getText().toString());
                float a = new Integer(et4.getText().toString());
                float end;
                end = (float) (((s1 + s2 + s3) / 7.5) + (a / 10));
                if (end <= 40) {
                    end = (40 - end) * 2;
                    result.setText("The marks needed to pass in your end semester:  " + end);
                } else {
                    end = (end - 40) / 2;
                    result.setText("Additional marks that you have :" + end);
                }

            }
        });



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_vi, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
 
Share this answer
 
Comments
Richard MacCutchan 11-Nov-15 4:52am    
As you see, you cannot build a Rolls-Royce before you understand how to build a Hindustan Ambassador.
[no name] 11-Nov-15 8:47am    
Yes Sir, it is true and I understand it now.Thank you for your kind help and guidance.
Afzaal Ahmad Zeeshan 11-Nov-15 13:16pm    
Great thing that you have actually understood our concern and tip. Good luck, do visit us again if you need any more recommendations, but do try to Google it! ;-)
[no name] 11-Nov-15 23:47pm    
Thank you Sir for your kind help and encouragement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900