Unfortunately, APP Has Stopped after added ADMOB - java

I am trying to add adMob ad in my android application, but it gives me unfortunately stopped error,
I am not expert in android program so dont know whats wrong in aap.
HomeActivity
package com.innobee.finddifferences;
import com.google.android.gms.ads.*;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.innobee.finddifferences.utility.Prefs;
public class HomeActivity extends Activity{
private int mLevelDuration; //Max Duration of the level in seconds
private Button mBtnResume;
private Button mBtnStart;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
mLevelDuration = getResources().getInteger(R.integer.levelDuration);
mLevelDuration = mLevelDuration * 1000;
mBtnStart = (Button)findViewById(R.id.btnStart);
mBtnStart.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Prefs.clearPref(getApplicationContext());
Prefs.setStagePref(getApplicationContext(), 1);
Intent play = new Intent(HomeActivity.this,
PlayActivity.class);
startActivity(play);
}
});
mBtnResume = (Button)findViewById(R.id.btnResume);
mBtnResume.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent play = new Intent(HomeActivity.this,
PlayActivity.class);
startActivity(play);
}
});
if(Prefs.getResumePref(getApplicationContext()) == mLevelDuration) {
mBtnResume.setVisibility(View.INVISIBLE);
}
else {
mBtnResume.setVisibility(View.VISIBLE);
}
}
#Override
protected void onRestart() {
super.onRestart();
//Show/hide resume button
if(Prefs.getResumePref(getApplicationContext()) == mLevelDuration) {
mBtnResume.setVisibility(View.INVISIBLE);
}
else {
mBtnResume.setVisibility(View.VISIBLE);
}
}
}
activity_home
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:background="#drawable/background"
android:gravity="bottom"
android:orientation="vertical" >
<Button
android:id="#+id/btnStart"
android:layout_width="209dip"
android:layout_height="55dip"
android:layout_marginBottom="30dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_start" />
<Button
android:id="#+id/btnResume"
android:layout_width="209dip"
android:layout_height="55dip"
android:layout_gravity="center_horizontal"
android:background="#drawable/button_resume"
android:layout_marginBottom="50dip"
android:visibility="gone" />
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="ca-app-pub-1504309466120108/6661079420"
ads:adSize="BANNER"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.innobee.finddifferences"
android:versionCode="4"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme.NoTitle" >
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<activity
android:name="com.innobee.finddifferences.HomeActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
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="com.innobee.finddifferences.NextGameActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.Transparent"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.SummaryActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.LostActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.StagePickActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.PlayActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity
android:name="com.innobee.finddifferences.ListMobileActivity"
android:screenOrientation="portrait"
android:theme="#style/AppBaseTheme.NoTitle"
android:configChanges="orientation|keyboardHidden" >
</activity>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
LogCat
11-30 22:52:47.121: E/AndroidRuntime(1282): at com.innobee.finddifferences.HomeActivity.onCreate(HomeActivity.java:21)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.Activity.performCreate(Activity.java:5104)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-30 22:52:47.121: E/AndroidRuntime(1282): ... 11 more
11-30 22:52:47.121: E/AndroidRuntime(1282): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.ads.AdView" on path: /data/app/com.innobee.finddifferences-1.apk
11-30 22:52:47.121: E/AndroidRuntime(1282): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
11-30 22:52:47.121: E/AndroidRuntime(1282): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11-30 22:52:47.121: E/AndroidRuntime(1282): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
11-30 22:52:47.121: E/AndroidRuntime(1282): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-30 22:52:47.121: E/AndroidRuntime(1282): ... 21 more
Thank you

The error might come from the wrong activity, you listed in your manifest, use this one:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
Still, as I said in my comment you should use minSDK="9" with the latest version of Google Services, otherwise this can lead to problems as well

Related

Intent error when I click the button - why?

I am having troubles and I can't figure out what the problem is.
There is no alert in my code, neither a red line or something.
HotelMapActivity.java
public class HotelMapActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map_hotel);
}
public void onClick(View v){
Intent intent = null;
switch (v.getId()){
case R.id.button1:
intent = new Intent(this, Map1.class);
break;
}
startActivity(intent);
}
}
This my button xml layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.together.Activities.Map.HotelMapActivity">
<android.support.v7.widget.AppCompatButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:onClick="onClick"
tools:context=".Activities.Map.HotelMapActivity"
android:text="google map"/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/button1"
android:onClick="onClick"
tools:context=".Activities.Map.HotelMapActivity"
android:text="place"/>
<android.support.v7.widget.AppCompatButton
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#id/button2"
android:onClick="onClick"
tools:context=".Activities.Map.HotelMapActivity"
android:text="Geo coding"/>
</RelativeLayout>
This is my Map1 Class
public class Map1 extends AppCompatActivity implements OnMapReadyCallback {
SupportMapFragment fragment;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map1);
fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fragment1);
fragment.getMapAsync(this);
}
//비동기적인 방식으로 구글맵을 생성
#Override
public void onMapReady(GoogleMap map) {
//지도 종류
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//현재 위치 표현 옵션
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
map.setMyLocationEnabled(true);
//줌컨트롤 표시 여부 ( 1 ~ 21 )
map.getUiSettings().setZoomControlsEnabled(true);
}
This is my Map1 activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context="com.example.together.Activities.Map.Map1">
<fragment
android:id="#+id/fragment1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="333dp"
android:layout_height="465dp"
android:layout_marginStart="36dp"
android:layout_marginTop="132dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I want to know what makes error occured
because nothing show to me what error is
This is my error code
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class fragment
Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
at com.google.maps.api.android.lib6.drd.p.b(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):22)
at com.google.maps.api.android.lib6.auth.d.a(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):10)
at com.google.maps.api.android.lib6.impl.d.a(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):41)
at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):61)
at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):25)
at com.google.android.gms.maps.internal.j.a(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):73)
at hm.onTransact(:com.google.android.gms.dynamite_mapsdynamite#17455084#17.4.55 (100700-248795830):4)
at android.os.Binder.transact(Binder.java:667)
at com.google.android.gms.internal.maps.zza.transactAndReadException(Unknown Source:7)
at com.google.android.gms.maps.internal.zzf.zzc(Unknown Source:8)
at com.google.android.gms.maps.MapFragment$zzb.zzc(Unknown Source:31)
at com.google.android.gms.maps.MapFragment$zzb.createDelegate(Unknown Source:2)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.zza(Unknown Source:44)
at com.google.android.gms.dynamic.DeferredLifecycleHelper.onInflate(Unknown Source:5)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source:44)
at android.app.Fragment.onInflate(Fragment.java:1443)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3555)
at android.app.FragmentController.onCreateView(FragmentController.java:102)
at android.app.Activity.onCreateView(Activity.java:6323)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
2019-06-07 20:34:58.118 31313-31313/com.example.blogapp E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.together.Activities.Map.Map1.onCreate(Map1.java:22)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
This is my Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.together">
<!-- 맵 이용하기 위함 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 다음 지도 -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 대략적인 위치 참조 권한 -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 정확한 위치 참조 권한 -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="i input my key in here" />
<activity android:name=".Activities.Map.Map1"></activity>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<activity android:name=".Activities.MyPetInfo.MyPetRegActivity" />
<activity android:name=".Activities.MyPetInfo.MyPetListActivity" />
<activity android:name=".Activities.Petching.MatchesActivity" />
<activity android:name=".Activities.Petching.SettingsActivity" />
<activity android:name=".Activities.Map.HotelMapActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activities.GoodbyePet.GoodbyePetActivity" />
<activity android:name=".Activities.PetHospital.PetHospitalActivity" />
<activity android:name=".Activities.PetGroup.PetGroupActivity" />
<activity android:name=".Activities.Petching.PetchingActivity" />
<activity android:name=".Activities.PetHotel.PetHotelActivity" />
<activity android:name=".Activities.PetHotel.HotelListDataActivity" />
<activity android:name=".Activities.PetHotel.HotelDetailActivity" />
<activity android:name=".Activities.Chat.MessageActivity" />
<activity android:name=".Activities.Chat.ChatsActivity" />
<activity android:name=".Activities.OptionActivity" />
<activity android:name=".Activities.FollowersActivity" />
<activity android:name=".Activities.EditProfileActivity" />
<activity android:name=".Activities.CommentsActivity" />
<activity android:name=".Activities.LoginActivity" />
<activity android:name=".Activities.RegisterActivity" />
<activity android:name=".Activities.PostActivity" />
<activity android:name=".Activities.HomeActivity" />
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="#style/Base.Theme.AppCompat" />
</application>
</manifest>
Add the key on your AndroidManifest:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>
Try below code
android:name="com.google.android.gms.maps.MapFragment"
to
class="com.google.android.gms.maps.SupportMapFragment"
Because in your Java file you used the
fragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragment1);
fragment.getMapAsync(this);
MapFragment does not casting into SupportMapFragment.
I hope its work for you.
There have been recent updates to the google API. The google API client has also been updated. google-api-client.

Issues with "R.” in Android Studio

already performed clean project, rebuild project, analysed and inspected code but it does not resolve the issue. This started when making "Slash Screen" i check my XML files it looks good to me, but started to realize in every .Java class i created symbol R. was underlined with red try everything i can think of....
`package com.example.dom.myapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splashscreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread() {
public void run() {
try
{
sleep(4000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
finally
{
Intent myactivity = new Intent("com.example.dom.MAINACTIVITY");
startActivity(myactivity);
}
}
};
timer.start();
}
}`
Here's my Splash layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/front"
>
</LinearLayout>
Here's my LogCat
04-27 18:27:49.869 12888-12888/? E/Zygote: MountEmulatedStorage()
04-27 18:27:49.869 12888-12888/? E/Zygote: v2
04-27 18:27:49.879 12888-12888/? E/SELinux: [DEBUG] get_category: variable seinfo: default sensitivity: NULL, cateogry: NULL
04-27 18:27:55.679 12888-12945/com.example.dom.myapp E/OpenGLRenderer: SFEffectCache:clear(), mSize = 0
Here's my AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.dom.myapp">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ActivityOne"></activity>
<activity android:name=".ActivityTwo"></activity>
<activity android:name=".ActivityThree"></activity>
<activity android:name=".ActivityFour"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
In splash layout do this
android:background="#+id/drawable/front" must be android:background="#drawable/front" remove this #+id/
looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/front"
>
</LinearLayout>

on Click function does not work in my application

I am trying to show another activity by clicking a button with Intent class but it stills gives error which is
" unfortunately my application has stopped"
and I think the code is correct
this is the `main activity class
course=(EditText) findViewById(R.id.editText);
hour=(EditText) findViewById(R.id.editText1);
add= (Button) findViewById(R.id.button);
view_= (Button) findViewById(R.id.button1);
view_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,ViewActivity.class);
startActivity(intent);
}
});
}
}
and this is ViewActivity class
TextView tv;
Button ed, de, view_;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view);
tv = (TextView) findViewById(R.id.details);
ed = (Button) findViewById(R.id.ed);
de = (Button) findViewById(R.id.delete);
view_= (Button) findViewById(R.id.button1);
Intent intent = getIntent();
view_.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
In additional I had added the .ViewActivity on the AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewActivity" />
</application>'
locat >>
FATAL EXCEPTION: main
Process: com.example.android.intent, PID: 11316
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.intent/com.example.android.intent.ViewActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.android.intent.ViewActivity.onCreate(ViewActivity.java:34)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5001) 
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:785) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
at dalvik.system.NativeStart.main(Native Method) 
view layout file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="80dp"
android:layout_height="50dp" >
<TextView
android:text="Course"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="#+id/course"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:textSize="24sp" />
<TextView
android:text="Hour"
android:layout_width="80dp"
android:layout_height="50dp"
android:id="#+id/hour"
android:layout_marginLeft="170dp"
android:layout_marginTop="10dp"
android:textSize="24sp"
android:layout_marginRight="30dp" />
</TableRow>
</TableLayout>
<Button
android:text="Edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="45dp"
android:id="#+id/ed"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="38dp"
android:layout_marginStart="38dp"
android:onClick="" />
<Button
android:text="Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="19dp"
android:layout_marginEnd="19dp"
android:id="#+id/delete"
android:layout_alignBaseline="#+id/ed"
android:layout_alignBottom="#+id/ed"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="" />
<TextView
android:layout_width="350dp"
android:layout_height="350dp"
android:id="#+id/details"
android:layout_above="#+id/delete"
android:layout_centerHorizontal="true" />
<Button
android:text="Refresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/delete"
android:layout_toLeftOf="#+id/delete"
android:layout_toStartOf="#+id/delete"
android:layout_marginRight="28dp"
android:layout_marginEnd="28dp"
android:id="#+id/button4"
android:onClick="" />
Can anyone help , thanks :)
Change your manifest like this,You added the ViewActivity inside another activity.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name = ".ViewActivity"/>
</application>'
Add this to your view layout,
<Button
android:text="Close View Activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button1" />
You haven't close the activity tag. Change AndroidManifest.xml to:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ViewActivity">
</activity>
</application>
Change this
view_= (Button) findViewById(R.id.button1);
To
view_= (Button) findViewById(R.id.button4);
There is no Button button1 in your ViewActivity class's XML, so when you try to access button1, NullPointerException occurs.
Try this in your manifest. You put one activity in another. Put seperate.
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewActivity" />
</application>

How can i solve this java lang error?

I am trying to solve this java lang error:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sebasdeldihotmail.mediocre11/com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity}: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2039)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2153)
at android.app.ActivityThread.access$700(ActivityThread.java:137)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5031)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity
at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2030)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2153)
            at android.app.ActivityThread.access$700(ActivityThread.java:137)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5031)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
            at dalvik.system.NativeStart.main(Native Method)
i have checked again and again the code and i can't find what is making the app crash, maybe some fresh eyes can help to find the issue.
Here is the SignUpOrSignIn class
public class SignUpOrLogInActivity extends Fragment {
private static final String TAG = "MainFragment";
Button signIn;
Button signUp;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.signinorsignup_activity,container,false);
Button signIn = (Button)root.findViewById(R.id.login);
signIn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(getActivity(), LoginActivity.class));
}
});
Button signUp = (Button)root.findViewById(R.id.signup);
signUp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(getActivity(),SignUpActivity.class));
}
});
return root;
}
private void onSessionStateChange(Session session, Session state, Exception exception) {
if (state.isOpened()) {
Log.i(TAG, "Logged in...");
} else if (state.isClosed()) {
Log.i(TAG, "Logged out...");
}
}
}
and here is the layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#67AAE4">
<Button
android:id="#+id/signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign Up"/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"/>
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
</LinearLayout>
MANIFEST
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
android:label="#string/app_name" >
</activity>
<activity android:name=".SignUpOrLogInActivity"
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=".DispatchActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name="com.facebook.LoginActivity"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
</application>
</manifest>
"CORRECTED MANIFEST"
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sebasdeldihotmail.mediocre11" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
android:name=".ParseStarter">
<activity
android:screenOrientation="portrait"
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 >
<activity android:name=".DispatchActivity"/>
<activity android:name=".LoginActivity" />
<activity android:name=".SignUpActivity" />
<activity android:name="com.facebook.LoginActivity"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id"/>
</application>
</manifest>
Can anyone figure out what is making the app crash?
Thanks very much for reading :)
Your SignUpOrLogInActivity extends Fragment. I'm assuming, based on the name, that this class is declared in the manifest as an Activity, which makes Android expect it to be a sub-class of Activity.
A Fragment must be contained in an Activity, so you need to create a class that extends Activity and contains your Fragment (which I would rename to something that doesn't contain the word Activity, since it's confusing). Your Android manifest should declare that activity class as the activity from which your app is launched.
SignUpOrLogInActivity extends Fragment
this is a fragment, and you are casting it to an activity.
You need to typecast it to a fragment for it to work
Caused by: java.lang.ClassCastException: com.sebasdeldihotmail.mediocre11.SignUpOrLogInActivity cannot be cast to android.app.Activity

Android - ClassNotFoundException (TwitterAPI)

Okay so I've been messing around with the Twitter API, and all of a sudden I've started to get the ClassNotFoundException error code when I try and enter the Activity which has my login box to sign into Twitter.
Here's the error code.
2398-2398/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
07-05 02:19:30.138 2398-2398/josh.com.twitterapi E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: josh.com.twitterapi.LoginActivity
at josh.com.twitterapi.NavigationDrawerFragment.selectItem(NavigationDrawerFragment.java:204)
at josh.com.twitterapi.NavigationDrawerFragment.access$000(NavigationDrawerFragment.java:32)
at josh.com.twitterapi.NavigationDrawerFragment$1.onItemClick(NavigationDrawerFragment.java:99)
at android.widget.AdapterView.performItemClick(AdapterView.java:301)
at android.widget.AbsListView.performItemClick(AbsListView.java:1280)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3071)
at android.widget.AbsListView$1.run(AbsListView.java:3973)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
07-05 02:21:03.973 3223-3223/josh.com.twitterapi E/dalvikvm﹕ Could not find class 'josh.com.twitterapi.LoginActivity', referenced from method josh.com.twitterapi.NavigationDrawerFragment.selectItem
This is my LoginActivity.java.
package josh.com.socialme;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import com.codepath.oauth.OAuthLoginActivity;
public class LoginActivity extends OAuthLoginActivity<TwitterClient> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
// Inflate the menu; this adds items to the action bar if it is present.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
// OAuth authenticated successfully, launch primary authenticated activity
// i.e Display application "homepage"
#Override
public void onLoginSuccess() {
// Intent i = new Intent(this, PhotosActivity.class);
// startActivity(i);
}
// OAuth authentication flow failed, handle the error
// i.e Display an error dialog or toast
#Override
public void onLoginFailure(Exception e) {
e.printStackTrace();
}
// Click handler method for the button used to start OAuth flow
// Uses the client to initiate OAuth authorization
// This should be tied to a button used to login
public void loginToRest(View view) {
getClient().connect();
}
}
This is my AndroidManifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
And this is my method I use to get to the activity.
private void selectItem(int position) {
// Handle Navigation Options
Intent intent;
switch (position) {
case 1:
intent = new Intent(getActivity(), Feed.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
case 2:
intent = new Intent(getActivity(), LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getActivity().startActivity(intent);
break;
}
}
I would greatly appreciate it if someone could point me towards the right direction.
Kind regards,
Josh
(AndroidManifest.xml as requested)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="josh.com.socialme" >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<activity
android:name=".Hub"
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=".Feed"
android:label="#string/title_activity_feed" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_login_activity" >
</activity>
</application>
</manifest>

Categories